【问题标题】:Difference between --static and -static LD_FLAGS in Makefile.amMakefile.am 中 --static 和 -static LD_FLAGS 的区别
【发布时间】: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


    【解决方案1】:

    测试库从你的构建测试库请求静态库。它应该在 Makefile.am 中定义如下

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

    如果您在 name_LDFLAGS 中声明 -static 标志。我们定义 -static 是为了链接项目上的动态库。

    【讨论】:

      猜你喜欢
      • 2012-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      • 2016-06-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多