When compiling our project, we create several archives (static libraries), say liby.a
and libz.a
that each contains an object file defining a funct
You could try (ld(2)):
--whole-archive
For each archive mentioned on the command line after the --whole-archive option, include every object file in the
archive in the link, rather than searching the archive for the required object files. This is normally used to turn
an archive file into a shared library, forcing every object to be included in the resulting shared library. This
option may be used more than once.
(gcc -Wl,--whole-archive)
Plus, you should put -Wl,--no-whole-archive
at the end of the library list. (as said by Dmitry Yudakov in the comment below)