Stack Exchange Network
Stack Exchange network consists of 183 Q&A communities including
Stack Overflow
, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Visit Stack Exchange
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.
Sign up to join this community
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I want to print a pixel on the screen using C language. When I write code and compile it shows
graphics.h:No such file or directory
I found that gcc doesn't have the "graphics.h" header file.
How can I add graphics.h to the gcc compiler?
the
<
and
>
will by default search in
/usr/include
for the specified files, which is why "stdio.h" always just works because that is found in
/usr/include/
in your .c file if you have
# include "whatever.h"
then it will only search in the current folder the .c file resides in at compile time to find whatever.h. So if you did # include "stdio.h"
you would get not found, but if you did # include "/usr/include/stdio.h"
that would work and is equivalent to # include <stdio.h>
.
use gcc -I/path_to_wherever -L/path_to_wherever myprogram.c -o myprogram.x
to compile to let gcc know where else to look for your .h files with the -I
option and for lib files (.a or .so) with -L
when in doubt, use -I
and -L
to explicitly tell gcc where the .h file is.
also there's no space after -I
or -L
when providing the path.
with the above out of the way, you need to have whatever-devel
package installed, in whatever folder, which then provides graphics.h
and the accompanying shared object libgraphics.so
or the static library libgraphics.a
. The compiled code to whatever function you use out of graphics.h
will exist in either the accompanying .so or .a file that you need to also reference at compile time to create a working executable.
you don't add graphics.h
to the compiler, it is an independent piece of code that you reference from yours... you tell gcc to compile your .c file and reference these supporting libraries i.e. graphics.h with -I and -L
your compile line will be something like
gcc myprogram.h -o myprogram.x -I/path_to_graphics.h_location -L/path_to_graphics.so_location -lgraphics
the lowercase -l
will say link with whatever library, just like -lm
is link with the math library.
If you want to use graphics.h on Ubuntu platform you need to compile and install libgraph. It is the implementation of turbo c graphics API on Linux using SDL.
Follow bellow steps