如何在 iPhone 的 XCode 中为不同的构建配置文件链接不同的预编译库?

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

How to link different precompiled libraries for different build profiles in XCode for iPhone?

iphonexcodestatic-linking

提问by CVertex

My client is providing me with two precompiled libraries, blah-device.a and blah-simulator.a. How do I tell xcode to use blah-device.a in Device compilation mode and simulator in Simulator compilation mode?

我的客户为我提供了两个预编译库,blah-device.a 和 blah-simulator.a。我如何告诉 xcode 在设备编译模式下使用 blah-device.a,在模拟器编译模式下使用模拟器?

My client gives me these instructions

我的客户给了我这些说明

  1. Open the Targets group (in the Groups & Files panel), right-click the project icon, then select Add > Existing Frameworks.
  2. In the Linked Libraries section, click the Add Libraries icon (+) icon, then click Add Other.
  3. Select either blah-device.a (for developing directly on the iPhone device) or blah-simulator.a (for developing on the iPhone Simulator), then click Add.
  1. 打开目标组(在组和文件面板中),右键单击项目图标,然后选择添加 > 现有框架。
  2. 在链接库部分,单击添加库图标 (+) 图标,然后单击添加其他。
  3. 选择 blah-device.a(用于直接在 iPhone 设备上开发)或 blah-simulator.a(用于在 iPhone 模拟器上开发),然后单击添加。

I already copied the header file in there, however these instructions don't make building easy with different profiles.

我已经在那里复制了头文件,但是这些说明不会使使用不同配置文件的构建变得容易。

How do I get Xcode to link blah-device.a when building with the DEVICE profiles and blah-simulator.a when building with the SIMULATOR profiles?

在使用 DEVICE 配置文件构建时如何让 Xcode 链接 blah-device.a,在使用 SIMULATOR 配置文件构建时如何让 blah-simulator.a 链接?

Any help is greatly appreciated.

任何帮助是极大的赞赏。

采纳答案by Kamchatka

There is an easier way to do that. You can duplicate the "Library Search Paths" under one target and set a different architecture for each one. You can then set a different path for simulator and devices.

有一种更简单的方法可以做到这一点。您可以在一个目标下复制“库搜索路径”,并为每个目标设置不同的架构。然后,您可以为模拟器和设备设置不同的路径。

回答by Kevin Depue

For future reference, a good way to handle situations like this is to glob the different architecture .a's into a single one that you can include in XCode. You can do this with the lipocommand line tool:

为了将来参考,处理此类情况的一种好方法是将不同的架构 .a 合并为一个可以包含在 XCode 中的架构。您可以使用lipo命令行工具执行此操作:

lipo libx.a liby.a -create -output libz.a

脂质 libx.a liby.a -create -output libz.a

If libx.a is armv6 and armv7 and liby.a is i386 for example, the resulting library, libz.a, will be armv6, armv7, and i386.

例如,如果 libx.a 是 armv6 和 armv7,而 liby.a 是 i386,则生成的库 libz.a 将是 armv6、armv7 和 i386。

You can also inspect a .a file via lipo -info.

您还可以通过 lipo -info 检查 .a 文件。

Hope this helps. :)

希望这可以帮助。:)

回答by Ramin

The easiest way would be to create two separate targets by duplicating your existing one. Name one "Foo Device" and the other "Foo Simulator." Then right-click on the blah-device.a in XCode, select the Targets tab and make sure the "Foo Device" target is checked ON and the "Foo Simulator" target is checked OFF.

最简单的方法是通过复制现有的目标来创建两个单独的目标。将一个命名为“Foo Device”,另一个命名为“Foo Simulator”。然后右键单击 XCode 中的 blah-device.a,选择 Targets 选项卡并确保选中“Foo Device”目标并选中“Foo Simulator”目标关闭。

Repeat for balah-simulator.a but this time "Foo Device" target is OFF and "Foo Simulator" target is checked ON.

对 balah-simulator.a 重复,但这次“Foo Device”目标关闭,“Foo Simulator”目标被选中。

Now whenever you want to do a simulator build make sure you select the Simulator from the Active SDK popup AND the "Foo Simulator" from the target popup. For device testing select Device AND the "Foo Device" target.

现在,无论何时您想要进行模拟器构建,请确保从 Active SDK 弹出窗口中选择模拟器,并从目标弹出窗口中选择“Foo Simulator”。对于设备测试,选择设备和“Foo Device”目标。

回答by dollar2048

you can use different linking path's for different libraries linking path's

您可以为不同的库使用不同的链接路径 链接路径的