【发布时间】:2012-09-21 13:36:31
【问题描述】:
我正在调试一个库链接问题,我遇到了一些我没想到的东西。这是问题所在。我正在使用构建工具来生成我的 Makefile,所以我只需要编写 Makefile.am。最终目标是构建一个共享库(srv.so)。我想静态链接一些库,所以我想使用“静态”标志到 LD。我的 Makefile.am 有这样的 LD_FLAGS
srv_la_LDFLAGS= -module -avoid-version
现在当我添加“静态”标志时,它变成了我们有两种不同的解释
第一
srv_la_LDFLAGS= -module -avoid-version -static /path/to/lib.a
第二次
srv_elastica_la_LDFLAGS= -module -avoid-version --static /path/to/lib.a
注意 --static 和 -static 之间的区别。
1st 生成一个运行 ar 的链接器行并尝试生成 srv.a 而不是 srv.so
/bin/bash ../../libtool --tag=CC --mode=link gcc -I../../include/
-Wno-unused-label -DMONGO_HAVE_STDINT -g -O2 -Wall -D_REENTRANT -g -O2 -Wall
-DCI_BUILD_MODULE -I/usr/local /c_icap/include/c_icap -module -avoid-version -z defs
-static /usr/local/lib/libmongoc.a -o srv.la -rpath /usr/local/lib/c_icap_modules
srv_la-srv.lo -lrt -lcre2 -lre2 -lcurl -lpthread -lbson
*** Warning: Linking the shared library srv_elastica.la against the
*** static library /usr/local/lib/libmongoc.a is not portable!
libtool: link: ar cru .libs/srv.a /usr/loc/lib/libmongoc.a
.libs/srv_la-srv.o
而 2nd 生成正确的链接器行(-shared)以输出 srv.so
/bin/bash ../../libtool --tag=CC --mode=link gcc -I../../include/ -Wno-unused-label
-DMONGO_HAVE_STDINT -g -O2 -Wall -D_REENTRANT -g -O2 -Wall -DCI_BUILD_MODULE -I/usr
/local/c_icap/include/c_icap -module -avoid-version -z defs --static /usr/local
/lib/libmongoc.a -o srv.la -rpath /usr/local/lib/c_icap_modules srv_la-srv.lo
-lrt -lcre2 -lre2 -lcurl -lpthread -lbson
*** Warning: Linking the shared library srv_elastica.la against the
*** static library /usr/local/lib/libmongoc.a is not portable!
libtool: link: gcc -shared -fPIC -DPIC .libs/srv_la-srv.o
/usr/local/lib/libmongoc.a -lrt -lcre2 -lre2 /usr/lib/x86_64-linux-gnu/libcurl.so
-lpthread -lbson -O2 -O2 -Wl,-soname -Wl,srv.so -o .libs/srv.so
这有点奇怪。ld 的手册页上没有提到这种类型。有什么帮助吗?
【问题讨论】:
标签: gcc linker makefile static-libraries