简体   繁体   English

Makefile.am中--static和-static LD_FLAGS之间的区别

[英]Difference between --static and -static LD_FLAGS in Makefile.am

I am working on debugging a library linking problem and i came across something i didnot expect. 我正在调试一个链接问题的库,我遇到了一些我没想到的东西。 Here is the issue. 这是问题所在。 I am using build tools to generate my Makefile and so i only have to write Makefile.am. 我正在使用构建工具来生成我的Makefile,所以我只需要编写Makefile.am。 The eventual goal is to build a shared library( srv.so ). 最终目标是构建共享库( srv.so )。 There are some libs that i want to link statically so i want to use the "static" flag to LD. 有一些libs我想静态链接所以我想使用LD的“静态”标志。 My Makefile.am has LD_FLAGS like this 我的Makefile.am有这样的LD_FLAGS

srv_la_LDFLAGS= -module -avoid-version

Now when i add the "static" flags it turns our there are 2 seperate interpretations of it 现在,当我添加“静态”标志时,我们对它进行了两次单独的解释

1st 1

srv_la_LDFLAGS= -module -avoid-version -static /path/to/lib.a

2nd 第2

srv_elastica_la_LDFLAGS= -module -avoid-version --static /path/to/lib.a

Notice the difference between --static and -static . 注意--static-static之间的区别。

The 1st one produces a linker line which run ar and attempts to produce srv.a instead of srv.so 一个生成一个链接行,它运行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

Whereas the 2nd one produces the correct linker line( -shared ) to output srv.so 第二一个产生正确的接头线(-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

This is kind of strange.There is nothing mentioned on manpage of ld of this sort. 这有点奇怪。在这种ld的手册页上没有提到。 Any help? 有帮助吗?

Test library requests static library from your build test library.it should define in Makefile.am follow as 测试库从构建测试库中请求静态库。它应该在Makefile.am中定义如下

srv_elastica_la_LDFLAGS= -module -avoid-version --static -L/path/to/lib_test_name -llib_test_name

In case you declare -static flag in name_LDFLAGS. 如果你在name_LDFLAGS中声明-static标志。 We define -static in order to link the dynamic libraries on project. 我们定义-static以链接项目上的动态库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM