iPhone 上链接器标志 force_load 的 xcode project-/target-settings-syntax
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3354864/
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
xcode project-/target-settings-syntax for linker flag force_load on iPhone
提问by Kaiserludi
I am confronted with the double bind. On the one hand, for one of the 3rd party static libraries my iPhone application uses, the linker flag -all_load
has to be set in the application project or target settings. Otherwise, the app crashes at run-time not finding some symbols called internally from the lib. On the other hand, for another 3rd party static lib, -all_load
must not be set on application level, or the app won't build thanks to a "duplicate symbols" linker error.
我面临双重束缚。一方面,对于我的 iPhone 应用程序使用的第 3 方静态库之一,-all_load
必须在应用程序项目或目标设置中设置链接器标志。否则,应用程序会在运行时崩溃,找不到从 lib 内部调用的某些符号。另一方面,对于另一个 3rd 方静态库,-all_load
不得在应用程序级别设置,否则由于“重复符号”链接器错误,应用程序将无法构建。
To solve this issue, I now want to use force_load
instead of load_all
, as it due to documentation it does the same like all_load
, but only for the passed path or lib-file, instead of all libs.
为了解决这个问题,我现在想使用force_load
而不是load_all
,因为它的文档与 类似all_load
,但仅用于传递的路径或库文件,而不是所有库。
The problem with force_load
is, I do not have a clue how to pass a path or file as parameter with it, when passing it via XCode project- or target-settings. All syntax-possibilities I tried either lead xcode to thinking it's another linker flag instead of a parameter to the previous one, or the linker throwing syntax related errors, or the flag simply does nothing at all.
问题force_load
是,当通过 XCode 项目或目标设置传递路径或文件时,我不知道如何将路径或文件作为参数传递给它。我尝试过的所有语法可能性要么导致 xcode 认为它是另一个链接器标志而不是前一个的参数,要么链接器抛出与语法相关的错误,或者该标志根本不执行任何操作。
I also opened the .pbxproj-file in a text-editor to edit it to the correct command line syntax manually. But when reloading the project with XCode, it auto-changes the syntax into interpreting the parameter to force_load
as a separate flag.
我还在文本编辑器中打开了 .pbxproj 文件,手动将其编辑为正确的命令行语法。但是当使用 XCode 重新加载项目时,它会自动将语法更改为将参数解释force_load
为单独的标志。
Anyone have an idea on this issue?
有人对这个问题有想法吗?
采纳答案by par
I just tried this. I've compiled a static armv6, armv7, and i386 fat binary of PCRE for use in my iPhone project. My project normally just has my library added to the project and that links fine. So I unchecked the target membership box for libpcre.a and rebuilt. As expected, I get a bunch of missing symbol linker errors for the pcre symbols. Then I opened the target settings window and edited the "Other Linker Flags" section. I added:
我刚试过这个。我已经编译了 PCRE 的静态 armv6、armv7 和 i386 胖二进制文件,以便在我的 iPhone 项目中使用。我的项目通常只是将我的库添加到项目中,并且链接正常。所以我取消选中 libpcre.a 的目标成员资格框并重建。正如预期的那样,我收到了一堆缺少 pcre 符号的符号链接器错误。然后我打开目标设置窗口并编辑“其他链接器标志”部分。我补充说:
-force_load lib/pcre/libpcre.a
The lib
directory is in the same directory as my project.xcodeproj file.
该lib
目录与我的 project.xcodeproj 文件位于同一目录中。
It linked fine so I know the force_load command worked (and I can see it added to the build flags when xcode builds the file).
它链接得很好,所以我知道 force_load 命令有效(当 xcode 构建文件时,我可以看到它添加到构建标志中)。
Hope that helps.
希望有帮助。
Update:
更新:
I also tried adding a system library to the "Other Linker Flags" line like so:
我还尝试将系统库添加到“其他链接器标志”行,如下所示:
-force_load src/pcre/libpcre.a -force_load ${SDKROOT}/usr/lib/libz.dylib
That worked too.
那也奏效了。
回答by Steven Kramer
I just added force_load to our project and all is fine using the simplest syntax possible. The library is a dependency built in the same project. The library is therefore included on the link command-line twice: once as a normal input file and once as an argument to -force_load. You might want to put quote characters around the argument.
我刚刚将 force_load 添加到我们的项目中,使用最简单的语法一切都很好。该库是在同一个项目中构建的依赖项。因此,该库两次包含在链接命令行中:一次作为普通输入文件,一次作为 -force_load 的参数。您可能希望在参数周围放置引号字符。
In fact, I've even got this working using configuration-dependent settings (because the path is obviously different for debug vs. release and device vs. simulator).
事实上,我什至使用依赖于配置的设置来完成这项工作(因为调试与发布以及设备与模拟器的路径明显不同)。
Good luck.
祝你好运。