设备与模拟器的 iPhone xcode 搜索路径?

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

iPhone xcode search path for device vs simulator?

iphonexcodesearchpath

提问by AlvinfromDiaspar

I am confused at this setting (Project -> Edit Active Target). The Search Paths can differ based on the SDK setting (simulator vs device).

我对这个设置感到困惑(项目 - > 编辑活动目标)。搜索路径可能因 SDK 设置(模拟器与设备)而异。

But if I provide both simulator and device paths, for lets say the Frameworks path, then i get linker errors. But it seems if I only provide the proper path for whichever SDK i have selected, then it builds fine!

但是,如果我同时提供模拟器和设备路径,比如框架路径,那么我会收到链接器错误。但似乎如果我只为我选择的任何 SDK 提供正确的路径,那么它构建得很好!

How can I keep both path settings? Currently Im having to cut and paste the appropriate path based on the SDK i have selected to build.

如何保留两个路径设置?目前,我必须根据我选择构建的 SDK 剪切和粘贴适当的路径。

Thanks!

谢谢!

采纳答案by phoebus

You should have two separate build target profiles set up, one for sim and one for device, rather than constantly editing the same one. That's kind of the point of targets.

您应该设置两个单独的构建目标配置文件,一个用于 sim,一个用于设备,而不是不断编辑同一个。这就是目标的重点。

回答by Rob Napier

Which kind of search path are you talking about? The system search paths are automatically handled for you, so I assume that your problem is some custom library.

你说的是哪种搜索路径?系统搜索路径会自动为您处理,因此我假设您的问题是某个自定义库。

There are two solutions. You can use conditional settings, or you can use universal libraries. I've grown to love universal libraries, but haven't had time to write up full instructions yet. The way they work is to build a static library for the simulator and for the device, and then use lipoto glue them together. You can then use the same library for both platforms. I really need to write up full instructions for this because it's very useful.

有两种解决方案。您可以使用条件设置,也可以使用通用库。我越来越喜欢通用库,但还没有时间写出完整的说明。它们的工作方式是为模拟器和设备构建一个静态库,然后lipo将它们粘合在一起。然后,您可以为两个平台使用相同的库。我真的需要为此编写完整的说明,因为它非常有用。

There are two more approaches. First you can use conditional settings. In xcconfig files (see my talkon why to use xcconfig files), you put something like this:

还有两种方法。首先,您可以使用条件设置。在 xcconfig 文件中(请参阅关于为什么使用 xcconfig 文件的讨论),您可以放置​​如下内容:

LD_FLAGS[sdk=iphonesimulator*] = -lsasl2

That links sasl2 just for the simulator. Set whatever you flag you need. Another solution is variable substitution:

这仅用于模拟器链接 sasl2。设置您需要的任何标志。另一种解决方案是变量替换:

HEADER_SEARCH_PATHS = "$(SRCROOT)/MyPackage/build/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/include"

This assumes that MyPackageis in a subdirectory of your project and it was built into the builddirectory. It'll look in, for example, Debug-iphoneosfor its variables.

这假设它MyPackage位于项目的子目录中,并且已内置到该build目录中。例如,它会查看Debug-iphoneos它的变量。

You can also do both of the above in the build pane, but I really recommend folks get away from the build pane for any serious project. Variable substitution works identically in the build pane, and conditional settings are accessible from right-clicking on a setting.

您也可以在构建窗格中执行上述两项操作,但我真的建议人们在任何严肃的项目中都不要使用构建窗格。变量替换在构建窗格中的工作方式相同,并且可以通过右键单击设置来访问条件设置。

回答by cdespinosa

If you're only using

如果您只使用

  • project headers
  • SDK framework headers
  • sqlite3 headers
  • 项目标题
  • SDK 框架标头
  • sqlite3 头文件

then your Header Search Paths should be empty. Xcode provides search paths for your project headers, SDK frameworks, and /usr/include/*.h automatically, and adjusts those for the framework in use.

那么你的 Header Search Paths 应该是空的。Xcode 自动为您的项目头文件、SDK 框架和 /usr/include/*.h 提供搜索路径,并针对正在使用的框架调整这些路径。

The only reasons to have custom Header Search Paths is when you have references to headers that are not in the SDK, are in "deep" locations in the SDK (such as in subdirectories of /usr/include or in buried frameworks), or are in other targets or projects your project cross-references.

拥有自定义标头搜索路径的唯一原因是当您引用了不在 SDK 中的标头、位于 SDK 中的“深层”位置(例如在 /usr/include 的子目录中或隐藏的框架中),或者是在其他目标或项目中您的项目交叉引用。

回答by Jeff Ames

Rob already hinted at this, but to clarify, here's how you'd set it using the build window.

Rob 已经暗示了这一点,但为了澄清,这里是您如何使用构建窗口设置它。

In the build settings window, select the setting you want to modify (like "Framework search paths"). Then click the gear in the lower left, and select "Add Build Setting Condition." Then you can add a value that applies only to iOS Simulator builds, and a second build setting condition to apply only to device builds.

在构建设置窗口中,选择要修改的设置(如“框架搜索路径”)。然后点击左下角的齿轮,选择“添加构建设置条件”。然后,您可以添加一个仅适用于 iOS 模拟器构建的值,以及仅适用于设备构建的第二个构建设置条件。