5

I'm trying to link in all unreferenced symbols from a few static libraries (my own libraries) for my C++ xcode app. I have tried all the properties related to 'strip' (by searching the properties for 'strip'), but the unreferenced symbols, specifically classes, are not linked in.

I have also tried the -r linker flag, but then the linker only complains with: 'ld: -r and -dead_strip cannot be used together'

I have tried adding '-no_dead_strip' to the linker flags, but then the linker just tells me '-no_dead_strip' is ignored.

I get the same results with both 'Apple LLVM' and 'LLVM GCC'.

So, my question is: what linker flag(s) or target properties should I use to switch off all dead code stripping and force unreferenced classes to be linked in?

Arno Duvenhage
  • 1,910
  • 17
  • 36
  • Maybe try the `--whole-archive` linker flag? – Kerrek SB Apr 30 '13 at 07:59
  • Android's NDK includes in its 'native glue' (static library) an empty function called `app_dummy()` that has no implementation. Calling this from the client-side (links against the mentioned library) apparently prevents stripping of symbols in that compilation unit. I was looking for a more elegant method, but seems there's none. – pauluss86 Jan 29 '14 at 21:52

1 Answers1

6

The standard linking mechanism - i.e. using the -l option to link a .a file will intelligently filter out object files that are not used, so the reason why the symbols are not present in the resultant binary is that they're not actually linked in.

If you want to get all the symbols from one archive, you can use the flag: -force_load libraryarchive, used like: -Wl,-force_load,libfoobar.a where libfoobar.a is the archive that you want to get all the symbols from.

In order to get all the symbols from the all archives, you should use the linker flag: -all_load, or if you're driving it from gcc/clang the flag -Wl,-all_load.

It produces hideous symbol tables, though!

Anya Shenanigans
  • 91,618
  • 3
  • 107
  • 122
  • 1
    With 'Dead Code Stripping' == No and 'Don't Dead-Strip Inits and Terms' == Yes, it did not work. But when I added the '-all_load' linker flag everything worked perfectly. Thanks!! – Arno Duvenhage Apr 30 '13 at 08:52