GLIB 安装后无法编译基本 GLIB 程序
我似乎无法使用 glib.h 编译这个基本程序...
#include glib.h
#include stdio.h
int main ()
{
return ((glib_major_version) || (glib_minor_version) || (glib_micro_version)); ;
return 0;
}
glib.h 位于 /usr/local/include/glib-2.0
所以我用
$ gcc -v -c -mcpu=v9 -I/usr/local/include/glib-2.0 testme2.c
现在我缺少 glibconfig.h 进行编译。但它在 /usr/local/lib/glib-2.0/include/glibconfig.h
奇怪的是 glibconfig.h 是 /usr/local/lib/glib-2.0/ 中唯一的文件include
目录,更奇怪的是它不在 /usr/local/include/glib-2.0
目录中
这是更多错误消息...
from /usr/local/include/glib-2.0/glib.h:32,
from testme.c:40:
:34:24: glibconfig.h: No such file or directory
这是 /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;
问题是 GCC 应该如何找到 glibconfig.h?
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 directory
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Glib 安装一个
glib-2.0.pc
文件,该文件描述了编译和链接所需的所有选项。请注意反引号内
pkg-config
的使用。Glib installs a
glib-2.0.pc
file that describes all the options necessary to compile and link.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
。
如果存在所需库的 .pc 文件,建议使用 pkg-config 而不是手动配置;如果您有特定需求或要使用的库不存在配置,则建议使用手动配置 正如您所看到的,pkg-config 告诉编译器将 glib-2.0 和 glib-2.0/include 目录都放入搜索路径中,就像根标头在全局路径中搜索一样。
您可以通过以下方式将 pkg-config 输出推断到编译命令中
<代码>
gcc `pkg-config ...` ...
.pc 文件通常安装在 /usr/include/pkgconfig 中
$ 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
glib 发行版中应该有一个名为
glib-config
的程序。如果您使用--cflags
参数运行它,它将列出所有必需的 gcc 标志。例如在我的系统上:如您所见,两个目录都被指定为包含目录。还有一个
--libs
标志,您可以将其传递给链接器,以便链接所有正确的库,并正确指定链接器搜索路径。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: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.