正确地将GLib标头包含在自动工具中 [英] Properly include GLib headers with autotools
问题描述
在正常的开发环境(ubuntu)中,与GLib-2.0链接时没有任何问题,但是,当我尝试在全新安装的Debian Squeeze上构建时,遇到了与GLib链接的错误.
In my normal dev environment (ubuntu), I don't have any issues linking against GLib-2.0, however when I attempt to build on fresh install of Debian Squeeze, I run into errors linking GLib.
configure.ac:
configure.ac:
...
AC_PROG_CC
AM_PROG_CC_C_O
CFLAGS="$CFLAGS -Wall -W -Wno-unused-parameter -std=c99 -pedantic"
PKG_CHECK_MODULES(MYAPP, [glib-2.0 >= 2.3.0 gthread-2.0])
LIBS="$LIBS $MYAPP_LIBS"
AC_CONFIG_FILES([Makefile src/Makefile])
AC_OUTPUT
Autotools似乎将正确的选项传递给了gcc:
Autotools appears to pass the correct options to gcc:
-I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -lgthread-2.0 -lglib-2.0
但是,运行make
时出现编译错误:undefined reference to 'g_list_free_full'
However, running make
I get a compile error: undefined reference to 'g_list_free_full'
要验证库是否已实际安装:
To verify the libraries are actually installed:
$ dpkg --get-selections | grep glib
libglib2.0-0 install
libglib2.0-data install
libglib2.0-dev install
有什么想法吗?
推荐答案
注意事项:
stormfs_LDADD = $(LIBS) $(LIBGCRYPT_LIBS)
>> stormfs_LDFLAGS = $(STORMFS_LIBS)
(请参见SO上链接器标志放在错误的位置.)
应该是:
(See Linker flags in wrong place here on SO.)
That ought to be:
stormfs_LDADD = ${LIBS} ${LIBGCRYPT_LIBS} ${STORMFS_LIBS}
(但是,这有点多余,因为LIBS和STORMFS_LIBS都包含相同的值,就像我查看生成的Makefile一样.)
(That is however sort of redundant because both LIBS and STORMFS_LIBS contain the same value, just as I looked at the generated Makefile.)
nm -D /usr/lib64/libglib-2.0.so | grep g_list_free_full
0000000000042740 T g_list_free_full
因此libglib.so(您的路径可能有所不同)至少在glib2-2.30.1中确实包含了g_list_free_full
.根据文档,此功能仅自glib2-2.28起可用,但是您的安装可能太旧了.最佳使用(最好是每个变量只有一个pkg依赖性,以简化对[deps]部分确切位置的检测):
So libglib.so (your path to it may vary) does include g_list_free_full
in at least glib2-2.30.1. According to the documentation, this function is only available since glib2-2.28, but your installation is likely just too old. Best use (and preferably just one pkg dependency per variable, to ease detection of what exactly of the [deps] part could not be found):
#configure.ac
PKG_CHECK_MODULES([libgthread], [gthread-2.0])
PKG_CHECK_MODULES([libglib], [glib-2.0 >= 2.28])
这篇关于正确地将GLib标头包含在自动工具中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!