简体   繁体   中英

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. The eventual goal is to build a shared library( srv.so ). There are some libs that i want to link statically so i want to use the "static" flag to LD. My Makefile.am has LD_FLAGS like this

srv_la_LDFLAGS= -module -avoid-version

Now when i add the "static" flags it turns our there are 2 seperate interpretations of it

1st

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

2nd

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

Notice the difference between --static and -static .

The 1st one produces a linker line which run ar and attempts to produce srv.a instead of 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

/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. Any help?

Test library requests static library from your build test library.it should define in Makefile.am follow as

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. We define -static in order to link the dynamic libraries on project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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