问题
Is it possible to tell autotools to link one of the libraries with -Wl,-whole-archive flag?
Makefile.am
bin_PROGRAMS = pktanon
pktanon_SOURCES = main.cpp
pktanon_DEPENDENCIES = $(lib_LIBRARIES)
pktanon_LDADD = libpktanon.a $(LDADD)
I need to link libpktanon.a with -Wl,-whole-archive flag, also I want make to execute something like this:
g++ -o pktanon main.o -Wl,-whole-archive libpktanon.a -Wl,-no-whole-archive -l...
(as in this question)
回答1:
I ran into a similar problem here. You can do this:
pktanon_LDFLAGS = -Wl,--whole-archive,libpktanon.a,--no-whole-archive
The issue is that Libtool doesn't guarantee the order of linker flags on the actual command line it executes, so you have to force it like this.
来源:https://stackoverflow.com/questions/22210903/autotools-and-wl-whole-archive