I can't seem to compile this basic program using glib.h...
#include glib.h
#include stdio.h
int main ()
{
return ((glib_major_version) || (glib_minor_version) || (glib_micro_version)); ;
return 0;
}
glib.h is located in /usr/local/include/glib-2.0
So I compiled with
$ gcc -v -c -mcpu=v9 -I/usr/local/include/glib-2.0 testme2.c
Now I get missing glibconfig.h. But it is in /usr/local/lib/glib-2.0/include/glibconfig.h
Strangely glibconfig.h is the only file in /usr/local/lib/glib-2.0/include
directory and more strangely it is not in /usr/local/include/glib-2.0
directory
Here are some more error messages...
from /usr/local/include/glib-2.0/glib.h:32,
from testme.c:40:
:34:24: glibconfig.h: No such file or director开发者_StackOverflowy
Here is an extract of /usr/local/include/glib-2.0/glib/gtypes.h
ifndef __G_TYPES_H__
define __G_TYPES_H__
include glibconfig.h
include glib/gmacros.h
G_BEGIN_DECLS
typedef char gchar;
typedef short gshort;
The question is how is GCC supposed to find glibconfig.h?
Glib installs a glib-2.0.pc
file that describes all the options necessary to compile and link.
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig g++ -c `pkg-config --cflags glib-2.0` testme2.c g++ -o testme2 testme.o `pkg-config --libs glib-2.0`
Note the use of pkg-config
within backquotes.
$ pkg-config --cflags --libs glib-2.0
-I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -lglib-2.0
It is advisable to use pkg-config instead of manual configuration if .pc files for desired libraries exist and fall back to manual configuration if you have specific needs or no configuration for the library you are going to use exists. As you can see, pkg-config tells the compiler to put both glib-2.0 and glib-2.0/include directories into the search path as the root header searches in the global path.
You can infer pkg-config output into your compilation command via
gcc `pkg-config ...` ...
.pc files are usually installed in /usr/include/pkgconfig
There should be a program in the glib distribution called glib-config
. If you run it with the --cflags
argument, it will list all the gcc flags necessary. For example on my system:
$ glib-config --cflags
-I/usr/include/glib-1.2 -I/usr/lib/glib/include
As you can see, both directories are specified as include directories. There is also a --libs
flags, which you can pass to your linker, so all the correct libs are linked, and the linker search path is correctly specified.
精彩评论