是否可以仅在使用设备而不是模拟器进行测试时使用静态库? [英] Is it possible to use a static library only when testing with device and not simulator?
问题描述
我有外部封闭的库,只能用armv7s(etc)编译。当我尝试编译模拟器时,显然它没有运行并显示一些错误。
我不想将这个库插入我的代码,除非我可以配置Xcode只在我用设备测试时使用这个库。
不幸的是,我试图用cocoapods做这个没有成功,我想知道是否有办法做到这一点?
I have external closed library that can compile with armv7s (etc) only. when I try to compile against simulator obviously its not running and display some errors. I don't want to insert this library to my code unless I can configure Xcode to use this library only when i test with a device. unfortunately, i tried to do it with cocoapods with no success and i wonder if there any way to do it?
推荐答案
是的,这可以做到。我有一个类似的问题,框架仅在模拟器中导致链接器错误,所以我设置我的项目只在构建设备时使用框架。
Yes, this can be done. I had a similar problem with a framework that caused linker errors only in the simulator so I setup up my project to only use the framework when building for a device.
以下假设您没有使用可可豆荚链接库。我不确定如果你需要改变什么。
The following assumes you are not using cocoa pods to link the library. I'm not sure what would need to be changed if you are.
- 选择目标并转到Build Phases选项卡。
- 在Link Binary With Libraries部分下,从列表中删除静态库。
- 转到Build Settings选项卡。
- 找到其他链接器标志设置。
- 双击Debug值。点击+并输入-lsomelibrary
- 代替somelibrary输入库的实际名称减去前导lib。不要包含扩展名。
- 选择Debug值并注意带圆圈+。单击+。
- 单击新的任何架构|任何SDK部分并将其更改为任何iOS模拟器SDK。
- 现在双击Any iOS Simulator SDK右侧的值并删除您添加的-lsomelibrary条目。
- Select your target and go to the Build Phases tab.
- Under the "Link Binary With Libraries" section, remove the static library from the list.
- Go to the Build Settings tab.
- Find the "Other Linker Flags" setting.
- Double-click on the Debug value. Tap the + and enter -lsomelibrary
- In place of "somelibrary" enter the actual name of your library minus the leading "lib". Do not include the extension.
- Select the Debug value and notice a little circled +. Click the +.
- Click on the new "Any Architecture | Any SDK" part and change it to "Any iOS Simulator SDK".
- Now double click on the value to the right of "Any iOS Simulator SDK" and remove the -lsomelibrary entry you added.
现在执行debug build。
Now do a debug build.
上述更改基本上意味着除了iOS模拟器版本之外,所有版本的库都已链接。
The above change basically means that the library is linked in for all builds except for iOS Simulator builds.
您可能还需要进行一些代码更改。任何对库中的头文件或其他符号的引用的代码都应该包含如下:
You will probably also need to make some code changes. Any code making any reference to header files or other symbols from the library should be wrapped as follows:
#if !TARGET_IPHONE_SIMULATOR
#import "somelibrary.h"
#endif
#if !TARGET_IPHONE_SIMULATOR
// Use stuff from the library
#endif
这篇关于是否可以仅在使用设备而不是模拟器进行测试时使用静态库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!