1

I've got C++ based static library that is built as a cmake project.

by itself it's compiled properly, but when being linked with another executable, many missing symbols shows up, which were supposedly be existed in that library because they all belong to another libraries that linked to it (2nd order libraries).

I've lookup for this issue over the web, and found out that the following flag may help me to avoid this memory size improvement and keep the missing symbols -Wl,--whole-archive.

So from the static library cmake file, every time i linked against another library I use the following command :

target_link_libraries(myStaticLib PUBLIC
  -Wl,--whole-archive
  Boost::system Boost::thread Boost::coroutine
  -Wl,--no-whole-archive
)

I Would have expected that all symbols from those linked sources will be inserted to the target library (myStaticLib)

However, i still see the same symbol appeared as missing.

Undefined symbols for architecture x86_64:
  "boost::coroutines::stack_traits::default_size()", referenced from:
      boost::coroutines::attributes::attributes() in myStaticLib.a(myFile1.o)
      boost::coroutines::attributes::attributes() in myStaticLib.a(myFile2.o)

Any idea how to resolve it ?

Zohar81
  • 4,554
  • 5
  • 29
  • 82
  • A static library is really nothing more than an archive of object files. Linking with a static library is like linking with the individual object files themselves. That means all the dependencies of the static library needs to be linked with as well. – Some programmer dude Sep 13 '21 at 09:06
  • @Someprogrammerdude, If I'll use dynamic library, should it link the dependencies along with the symbols ? – Zohar81 Sep 13 '21 at 09:52
  • 1
    `target_link_libraries` cannot combine several static libraries into the one, so the resulting library alone could be linked into executable. See [duplicate question](https://stackoverflow.com/questions/37924383/combining-several-static-libraries-into-one-using-cmake) about proper combining of static libraries. – Tsyvarev Sep 13 '21 at 10:00

0 Answers0