[英]Difference between --static and -static LD_FLAGS in Makefile.am
我正在调试一个链接问题的库,我遇到了一些我没想到的东西。 这是问题所在。 我正在使用构建工具来生成我的Makefile,所以我只需要编写Makefile.am。 最终目标是构建共享库( srv.so )。 有一些libs我想静态链接所以我想使用LD的“静态”标志。 我的Makefile.am有这样的LD_FLAGS
srv_la_LDFLAGS= -module -avoid-version
现在,当我添加“静态”标志时,我们对它进行了两次单独的解释
1
srv_la_LDFLAGS= -module -avoid-version -static /path/to/lib.a
第2
srv_elastica_la_LDFLAGS= -module -avoid-version --static /path/to/lib.a
注意--static和-static之间的区别。
第一个生成一个链接行,它运行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
而第二一个产生正确的接头线(-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的手册页上没有提到。 有帮助吗?
测试库从构建测试库中请求静态库。它应该在Makefile.am中定义如下
srv_elastica_la_LDFLAGS= -module -avoid-version --static -L/path/to/lib_test_name -llib_test_name
如果你在name_LDFLAGS中声明-static标志。 我们定义-static以链接项目上的动态库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.