如何在 xcode 中禁用 C++ 死代码剥离
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16294842/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to disable C++ dead code stripping in xcode
提问by Arno Duvenhage
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.
我正在尝试从一些静态库(我自己的库)中为我的 C++ xcode 应用程序链接所有未引用的符号。我已经尝试了所有与 'strip' 相关的属性(通过搜索 'strip' 的属性),但是未引用的符号,特别是类,没有链接。
I have also tried the -r linker flag, but then the linker only complains with: 'ld: -r and -dead_strip cannot be used together'
我也试过 -r 链接器标志,但是链接器只抱怨:'ld: -r 和 -dead_strip 不能一起使用'
I have tried adding '-no_dead_strip' to the linker flags, but then the linker just tells me '-no_dead_strip' is ignored.
我曾尝试将“-no_dead_strip”添加到链接器标志中,但是链接器只是告诉我“-no_dead_strip”被忽略了。
I get the same results with both 'Apple LLVM' and 'LLVM GCC'.
我用“Apple LLVM”和“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?
所以,我的问题是:我应该使用什么链接器标志或目标属性来关闭所有死代码剥离并强制链接未引用的类?
回答by Petesh
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.
标准链接机制——即使用-l
链接.a
文件的选项将智能地过滤掉未使用的目标文件,因此符号不存在于结果二进制文件中的原因是它们实际上并未链接。
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.
如果您想从一个档案中获取所有符号,您可以使用标志:-force_load libraryarchive
,使用方式如下:您想从中获取所有符号的档案-Wl,-force_load,libfoobar.a
在哪里libfoobar.a
。
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
.
为了从所有档案中获取所有符号,您应该使用链接器标志:-all_load
,或者如果您从gcc
/clang
标志驱动它-Wl,-all_load
。
It produces hideous symbol tables, though!
但是,它会生成可怕的符号表!