Xcode - 根据正在编译代码的设备修改库搜索路径

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5492346/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 20:42:18  来源:igfitidea点击:

Xcode - Modify Library Search Path Based on device which code is being compiled for

iphonexcodeios-simulatorxcode4

提问by Mick Walker

I am sure this has been asked before, however I have been banging my head against a brick wall all afternoon trying to figure out how to achieve this using XCode 4.

我确信以前有人问过这个问题,但是我整个下午都在用头撞砖墙,试图弄清楚如何使用 XCode 4 来实现这一点。

I have a lib which was distributed by a 3rd party. They actually ship 2 different versions, one for use in the simulator, and one for use with the actual device.

我有一个由第 3 方分发的库。他们实际上提供了两种不同的版本,一种用于模拟器,一种用于实际设备。

I would like to know, what is the recommended way for handling situations like this in XCode 4; in XCode 3, I could simply have specified a new target. I wish to avoid creating a fat binary via lipo containing both libs, but if that is the only feasible option available to me, then so be it.

我想知道,在 XCode 4 中处理这种情况的推荐方法是什么?在 XCode 3 中,我可以简单地指定一个新目标。我希望避免通过包含两个库的 lipo 创建一个胖二进制文件,但如果这是我唯一可行的选择,那么就这样吧。

Ideally what I would like to do is modify the Library Search path based upon the current device the project is being compiled for such as:

理想情况下,我想做的是根据正在编译项目的当前设备修改库搜索路径,例如:

Simulator: /path/to/simulator/lib.a

模拟器:/path/to/simulator/lib.a

Device /path/to/device/lib.a

设备 /path/to/device/lib.a

If I could automate the process so once I had set it up, it was transparent, all the better.

如果我可以自动化这个过程,那么一旦我设置了它,它就是透明的,那就更好了。

Many thanks for taking the time to read this.

非常感谢您花时间阅读本文。

采纳答案by Kendall Helmstetter Gelner

You can still create new targets in XCode4 - just go to your project in the navigator sidebar, select it and in the project editor you can select "new target".

您仍然可以在 XCode4 中创建新目标 - 只需在导航器侧栏中转到您的项目,选择它,然后在项目编辑器中选择“新目标”。

However I would actually recommend you use lipo to create a fat binary. I believe the simulator part gets stripped out as part of the build phase so it should not impact executable size.

但是,我实际上建议您使用 lipo 来创建一个胖二进制文件。我相信模拟器部分会作为构建阶段的一部分被剥离,因此它不应该影响可执行文件的大小。

回答by Yair

XCode define $(EFFECTIVE_PLATFORM_NAME)to be 'iphoneos' or 'iphonesimulator' base on the target "device". As long as your library path includes one of those strings, you can set LIBRARY_SEARCH_PATHSin your targets or project to something like:

XCode$(EFFECTIVE_PLATFORM_NAME)根据目标“设备”定义为“iphoneos”或“iphonesimulator”。只要您的库路径包含这些字符串之一,您就可以 LIBRARY_SEARCH_PATHS在目标或项目中设置为:

/path/to/$(EFFECTIVE_PLATFORM_NAME)/lib.a

Hint: you can see this in action by clicking "All" in Building Settings, and then selecting Editor > Show Setting Namesand Editor > Show Setting Definitionsin the menus. To see if the final value is what you expect, switch back to values using Editor > Show Setting Values.

提示:您可以通过单击“建筑设置”中的“全部”,然后在菜单中选择“编辑器”>“显示设置名称”和“编辑器”>“显示设置定义”来查看此操作。要查看最终值是否符合您的预期,请使用Editor > Show Setting Values切换回