xcode 带有库的 iOS 链接二进制文件仅用于调试

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

iOS Link Binary with library for debug only

iphoneobjective-ciosxcode

提问by John Lane

I have a bit of a problem with setting different configuration for my project. I have two versions of the same static library. One has logging enabled, the other doesn't.

我在为我的项目设置不同的配置时遇到了一些问题。我有同一个静态库的两个版本。一个启用了日志记录,另一个没有。

I am using two different xcconfig files for Debug vs. Release. In these files I specify the library and header search paths for the two variants of the static lib. So far so good.

我使用两个不同的 xcconfig 文件进行调试与发布。在这些文件中,我为静态库的两个变体指定了库和头文件搜索路径。到现在为止还挺好。

However, in my build settings I can't see a way to conditionally link the actual library. I.e use the debug variant for Debug and the release for Release.

但是,在我的构建设置中,我看不到有条件地链接实际库的方法。即使用调试变体进行调试,使用发布进行发布。

Any ideas?

有任何想法吗?

回答by Mike Weller

You need to link the library using the "Other Linker Flags" build setting, rather than the standard "Link Binary With Libraries" UI. The build setting can be changed depending on the configuration:

您需要使用“其他链接器标志”构建设置链接库,而不是使用标准的“链接二进制与库”UI。可以根据配置更改构建设置:

enter image description here

在此处输入图片说明

Click the triangle and you can give different values for Debug/Release. You will need to use the -lflag. For example, for a filename of libMyLib.ause the flag -lMyLib. You may need to edit the "Library Search Paths" to search the appropriate location.

单击三角形,您可以为调试/发布提供不同的值。您将需要使用该-l标志。例如,对于libMyLib.a使用标志的文件名-lMyLib。您可能需要编辑“图书馆搜索路径”以搜索适当的位置。

If the filenames for the debug and release version are the same and you don't want to change them, put them into their own lib/Debugand lib/Releasedirectories respectively. Then edit the "Library Search Paths" build setting adding either "$SRCROOT/lib/Debug"or "$SRCROOT/lib/Release"for the appropriate configuration.

如果调试版本和发布版本的文件名相同并且您不想更改它们,则将它们分别放入各自的目录lib/Debuglib/Release目录中。然后编辑“库搜索路径”构建设置,添加"$SRCROOT/lib/Debug""$SRCROOT/lib/Release"为适当的配置。