简体   繁体   中英

how to disable C++ dead code stripping in 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?

The standard linking mechanism - ie 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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM