I have a problem very similar to this question. I need to tell the linker to add the static lib, despite the fact that to reference to its symbols seems to be made.
The reason for that is that the library contains an function in .init or using ( __attribute__ ((constructor))) to perform its initialisation, which in turn, is going to call a register() function from the main program to register its functionality (read: pass other function pointers).
So despite the fact that no symbol from the library seems to be used in the main program, the main program will call functions from the library as soon as the latter are registered via the library init function.
But I am using libtool... So taking the example given in the previously mentionned question, I'd need to write something like:
bin_PROGRAMS = pktanon
pktanon_SOURCES = main.cpp
pktanon_DEPENDENCIES = $(lib_LIBRARIES)
pktanon_LDADD = libpktanon.la $(LDADD)
Note the "la" extension instead of "a" for the lib.
Now, how shall I pass the --whole-archive option to the linker? The answer suggested in the question assumes the path to the archive (.a file) is known... It does not feel right to hard code a path like .libs/libptanon.a in the Makefile.am...
And the linker does not like meeting a .la file in its whole-archive otpion if trying:
pktanon_LDFLAGS = -Wl,--whole-archive,libpktanon.la,--no-whole-archive
Any suggestions?