Reputation: 2207
"ar" -- is just tool to create archives.
And all static libraries of form "lib*.a" are in fact just archived compiled objects + additional file with symbol table, added there by "ranlib". No linking is performing during creation of such library.
So why do most of projects use ***_LDFLAGS
***_LIBADD
in their Makefile.am
during creation of such ("lib*.a" static library) archives?
Does automake ignore those flags (in case when they relate to any "lib*.a" static library), or does it in fact link something there?
Upvotes: 2
Views: 4203
Reputation: 560
Answer to your question Does automake ignore them
is: NO
That is completely true: ""ar" -- is just tool to create archives."
But, Automake does not ignore ***_LDFLAGS
***_LIBADD
in their Makefile.am
at all, otherwise what is point of having such flag if they are not making any sense for the build system!
From documentation (link give below):
library_LIBADD
’ variable should be used to list extra libtool objects (.lo files) or libtool libraries (.la) to add to library.library_LDFLAGS
’ variable is the place to list additional libtool linking flags, such as -version-info
, -static
, and a lot more.For more details, you should go through this Libtool Documentation for more clarity in these flags.
EDIT:
As your question is still generic, let me put it in two different scenario...
Static Lib is stand-alone:
***_LIBADD
could be not much useful, as mentioned in documentation: "the library_LIBADD
variable should be used to list extra libtool objects (.lo
files) or libtool libraries (.la
) to add to library"Makefile.am
.Static Lib is Dependent (not stand-alone)
***_LIBADD
flag is used to mentioned libs names which are required to build your current library.And about ***_LDFLAGS
, as mentioned in documentation, The library_LDFLAGS
variable is the place to list additional libtool linking flags for that library.
Few more additional links for your reference:
I hope this EDIT suffices what you're looking for.
PS: If you would read my answer carefully and went through documentation, you could have get the same data. Njoy. :)
Upvotes: 1
Reputation: 16305
So why do most of projects use
***_LDFLAGS
***_LIBADD
in their Makefile.am during creation of such ("lib*.a" static library) archives?
The GNU Build System is capable of creating dynamic and static libs (or both) determined at configure
time using the --enable-shared
and --enable-static
flags. As you guessed, _LDFLAGS
and _LIBADD
are more oriented to dynamic shared objects or program linkage than to the static linker. The static linker of libtool
is essentially another link pass that invokes ar
to create the archive (omitting all the flags). For example:
lib_LTLIBRARIES=libfoo.la
libfoo_la_SOURCES=$(SRCS)
libfoo_la_LDFLAGS=-Wl,-t
when both shared and static libs are generated outputs something like:
libtool: link: gcc -shared -fPIC -DPIC .libs/foo.o -g -O2 -Wl,-t -Wl,-soname -Wl,libfoo.so.0 -o .libs/libfoo.so.0.0.0
...
libtool: link: (cd ".libs" && rm -f "libfoo.so.0" && ln -s "libfoo.so.0.0.0" "libfoo.so.0")
libtool: link: (cd ".libs" && rm -f "libfoo.so" && ln -s "libfoo.so.0.0.0" "libfoo.so")
libtool: link: ar cru .libs/libfoo.a foo.o
libtool: link: ranlib .libs/libfoo.a
libtool: link: ( cd ".libs" && rm -f "libfoo.la" && ln -s "../libfoo.la" "libfoo.la" )
automake
does ignore _LDFLAGS
; however the script that performs the linking (libtool
) does not. It looks for flags that affect linking there also. For example:
lib_LTLIBRARIES=libfoo.la
libfoo_la_SOURCES=$(SRCS)
libfoo_la_LDFLAGS=-Wl,-t -static
will only generate a static lib, even if configure --disable-static
was run to generate the Makefile.
libtool
is just a wrapper script over the native compiler/linker tools for portability.
Upvotes: 3