Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to disable C++ dead code stripping in xcode

Tags:

c++

xcode

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?

like image 948
Arno Duvenhage Avatar asked Apr 30 '13 07:04

Arno Duvenhage


1 Answers

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!

like image 74
Petesh Avatar answered Oct 12 '22 13:10

Petesh