[英]iPhone static library Clang/LLVM error: non_lazy_symbol_pointers
After several hours of experimentation, I've managed to reduce the problem to the following example (C++): 经过几个小时的试验,我设法将问题简化为以下示例(C ++):
extern "C" void foo();
struct test
{
~test() { }
};
void doTest()
{
test t; // 1
foo(); // 2
}
This is being compiled for iOS devices in XCode 4.2, using the provided Clang compiler (Apple LLVM compiler 3.0) and the iOS 5.0 SDK. 正在使用提供的Clang编译器(Apple LLVM编译器3.0)和iOS 5.0 SDK在XCode 4.2中为iOS设备编译此文件。 The project is configured as a Cocoa Touch Static Library, and "Enable Linking With Shared Libraries" is set to No because I'm building an AIR native extension.
该项目配置为Cocoa Touch静态库,并且“启用与共享库的链接”设置为“否”,因为我正在构建AIR本机扩展。 The function
foo
is defined in another external library. 函数
foo
在另一个外部库中定义。 (In my actual project, this would be any of the C API functions defined by Adobe for use in AIR native extensions.) (在我的实际项目中,这将是Adobe定义用于AIR本机扩展的任何C API函数。)
When attempting to compile this code, I get back the error: 尝试编译此代码时,我得到了以下错误:
FATAL:incompatible feature used: section type non_lazy_symbol_pointers (must specify "-dynamic" to be used)
clang: error: assembler command failed with exit code 1 (use -v to see invocation)
The error goes away if I comment out either of the lines marked 1
or 2
above, or if I change the build setting "Enable Linking With Shared Libraries" to Yes. 如果我在上面标记为
1
或2
的行中注释掉了,或者将构建设置“启用与共享库的链接”更改为“是”,则错误消失了。 (However, if I change the build setting, then I get multiple ld warning: unexpected srelocation type 9
warnings when linking the library into the final project, and the application crashes when running on the device.) The build error also goes away if I remove the destructor from test
. (但是,如果更改构建设置,则会收到多个
ld warning: unexpected srelocation type 9
将库链接到最终项目时ld warning: unexpected srelocation type 9
警告,并且在设备上运行时应用程序崩溃。)从test
删除析构函数。
So: Is this a bug in Clang? 所以:这是Clang中的错误吗? Am I missing some all-important and undocumented build setting?
我是否缺少一些非常重要且未记录的构建设置? The interaction between an externally-provided function and a struct with a destructor is very peculiar, to say the least.
至少可以说,外部提供的函数与带有析构函数的结构之间的交互非常特殊。
After much searching, I finally stumbled across Richard Lord's excellent blog post on AIR native extensions . 经过大量搜索之后,我终于偶然发现了Richard Lord 在AIR本机扩展上的出色博客文章 。 It turns out that effective development requires use of a few flags that Adobe hasn't bothered to document yet (unless you count developer blog posts as documentation -- I don't).
事实证明,有效的开发需要使用Adobe尚未打扰的一些标志(除非您将开发人员博客文章视为文档,但我不认为)。
Long story short: 长话短说:
-platformsdk
option to point to the iOS SDK provided by Apple (example: -platformsdk /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk
). -platformsdk
选项指向Apple提供的iOS SDK(例如: -platformsdk /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk
)。 This will alleviate the unexpected srelocation type 9
warnings. unexpected srelocation type 9
警告。 Adobe's documentation states that -platformsdk is only for Android, but that's a lie. -platformoptions
option to specify an xml file containing additional linker arguments. -platformoptions
说明的-platformoptions
选项指定包含其他链接器参数的xml文件。 The format of this XML file is also undocumented, but a template can be found in the AIR SDK directory under templates/extensions/ios/platform-descriptor-template.xml
. templates/extensions/ios/platform-descriptor-template.xml
下找到一个templates/extensions/ios/platform-descriptor-template.xml
。 There's also an xsd schema in the same location. ld: warning: ARM function not 4-byte aligned
. ld: warning: ARM function not 4-byte aligned
。 This can apparently be safely ignored. -w
to the linker in the platformoptions file, but be aware that -w
silences all warnings, not just that one. -w
传递给platformoptions文件中的链接器来使该警告静音,但是请注意-w
使所有警告而不是仅使所有警告静音。 Further information can be found in these two blog posts by Rajorshi Ghosh, one of the Adobe engineers: 可以在Adobe工程师之一Rajorshi Ghosh的这两个博客文章中找到更多信息:
This still doesn't explain the weird interaction between "Enable Linking With Shared Libraries", externally defined functions, and destructors, but that's now reduced to a matter of curiosity rather than a blocking issue. 这仍然不能解释“启用与共享库的链接”,外部定义的函数和析构函数之间的怪异互动,但是现在这只是出于好奇而不是阻塞性问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.