Reputation: 3946
I am familiar with very simple g++ commands that compile and link programs, however when working with GTK+ I found the tutorial indicate that I should use pkg-config --cflags gtk+-2.0
Now when I type in pkg-config --cflags gtk+-2.0
to the terminal I get a list of libraries and files like this...
-pthread -I/usr/include/gtk-2.0 -I/usr/lib/x86_64-linux-gnu/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/harfbuzz
So my question is, what does the -I mean in front of a directory? For example -I/usr/include/libpng12
Upvotes: 0
Views: 2537
Reputation: 25
As the answers from @R Sahu @Klaus and @Yuushi explain, the -I dir
tells the compiler where to look for the #include header.h
file.
When the program is compiled, it will be linked. You will probably also need to tell the linker where to find the programs that support the functions in the #included headers. This is done with the -llibrary
flag. That is a lower case l not a one (1).
The pkg-config command references a set of files and will supply the compiler flags --cflags
and link flags --ldflags
if you supply the package name.
Put the returned -Includes before the source name(s) and the -l's after in your compile command request.
For other than casual, one-off programs, you should use make. The cflag and ldflag info can be put in variables in the Makefile
and referenced throughout your make script.
You can get a complete list of packages configured to pkg-config on your Ubuntu system with locate *.pc
Upvotes: 0
Reputation: 26040
-I
is simply adding to the paths to be searched for header files. Note that these are searched before system paths.
You can find pretty much all the options for gcc/g++
here. In this case, you want the Directory Search options specifically; see here. From that page:
-Idir
Add the directory dir to the head of the list of directories to be searched for header files. This can be used to override a system header file, substituting your own version, since these directories are searched before the system header file directories. However, you should not use this option to add directories that contain vendor-supplied system header files (use -isystem for that).
If you use more than one -I option, the directories are scanned in left-to-right order; the standard system directories come after. If a standard system include directory, or a directory specified with -isystem, is also specified with -I, the -I option is ignored. The directory is still searched but as a system directory at its normal position in the system include chain. This is to ensure that GCC's procedure to fix buggy system headers and the ordering for the include_next directive are not inadvertently changed. If you really need to change the search order for system directories, use the -nostdinc and/or -isystem options.
Upvotes: 2
Reputation: 25613
Please read the manual. All command line options are present there :-)
-I set the search path for libraries.
https://gcc.gnu.org/onlinedocs/cpp/Search-Path.html
Upvotes: 2
Reputation: 206607
The -I
flag is used to add directories to the list of directories to search for finding files in #include <>
statements.
In your case, when a file is included by using #include
, /usr/include/libpng12
will be one of the directories in which the pre-processor will search for the file.
Upvotes: 2