简体   繁体   English

iPhone静态库Clang / LLVM错误:non_lazy_symbol_pointers

[英]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. 如果我在上面标记为12的行中注释掉了,或者将构建设置“启用与共享库的链接”更改为“是”,则错误消失了。 (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: 长话短说:

  • Set "Enable Linking With Shared Libraries" to Yes. 将“启用与共享库的链接”设置为“是”。 Setting this to No is the single most pervasive piece of bad advice out there about developing AIR native extensions. 将此设置为No是关于开发AIR本机扩展的最普遍的坏建议。
  • Use ADT's -platformsdk option to point to the iOS SDK provided by Apple (example: -platformsdk /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk ). 使用ADT的-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. Adobe的文档指出-platformsdk仅适用于Android,但这是一个谎言。
  • When packaging the extension (that is, when building the ANE file), use the undocumented -platformoptions option to specify an xml file containing additional linker arguments. 在打包扩展名时(即,在构建ANE文件时),请使用未-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 . 该XML文件的格式也未记录,但是可以在AIR SDK目录中的templates/extensions/ios/platform-descriptor-template.xml下找到一个templates/extensions/ios/platform-descriptor-template.xml There's also an xsd schema in the same location. 在同一位置也有一个xsd模式。 This file allows you to specify whatever additional frameworks your extension uses, so you won't be limited to the default frameworks that the AIR SDK supports. 该文件允许您指定扩展使用的其他框架,因此您将不仅限于AIR SDK支持的默认框架。
  • Expect to see a new linker warning: ld: warning: ARM function not 4-byte aligned . 期望看到一个新的链接器警告: ld: warning: ARM function not 4-byte aligned This can apparently be safely ignored. 这显然可以安全地忽略。 Adobe is reportedly aware of the issue. 据报道,Adobe已意识到该问题。 I imagine that you can silence this warning by passing -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.

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