如何在 Xcode 项目设置中使用相对路径?

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

How do I use a relative path in Xcode project settings?

xcodepathrelative-path

提问by Shay

How do I use a relative path in Xcode project settings?

如何在 Xcode 项目设置中使用相对路径?

回答by cdespinosa

All paths in Build Settings are assumed relative to the directory that contains the .xcodeproj file. Use the standard Unix path tokens

假定构建设置中的所有路径都相对于包含 .xcodeproj 文件的目录。使用标准的 Unix 路径标记

.   project directory
..  parent directory

So if your project file is trunk/Mac/proj.xcodeproj, and your headers are in trunk/Headers/foo.h, you would add ../Headers to your Header Search Paths.

因此,如果您的项目文件是 trunk/Mac/proj.xcodeproj,并且您的头文件在 trunk/Headers/foo.h 中,您应该将 ../Headers 添加到您的 Header Search Paths 中。

回答by Mike Chen

Also there are two paths: $SRCROOTand $SDKROOT.

还有两个路径:$SRCROOT$SDKROOT

回答by ulu5

In the upper left corner next to the build/stop buttons, click on the name of your project and Edit Scheme...

在构建/停止按钮旁边的左上角,单击您的项目名称和 Edit Scheme...

In the left column, click on Run

在左栏中,单击运行

Click on Options

点击选项

Put a check next to Working Directory: Use custom working directory.

在工作目录旁边打勾:使用自定义工作目录。

You can then change the relative path to anywhere you want.

然后,您可以将相对路径更改为您想要的任何位置。

EDIT: This is for Xcode 4.1

编辑:这是针对 Xcode 4.1

回答by user3483663

For Xcode 5:

对于Xcode 5

Click on Product -> Scheme -> Edit Scheme.

单击产品 -> 方案 -> 编辑方案。

Then follow ulu5's instructions: Click "Run", Click on "Options", and check the box "Use custom working directory."

然后按照 ulu5 的说明进行操作:单击“运行”,单击“选项”,然后选中“使用自定义工作目录”框。

回答by orion elenzil

The various answers currently here which recommend setting the working directory when executing a project by editing the scheme and then choosing whatever directory you want are missing what seems like a key part of the question: Relative Path. If you just use the file navigator in the UI you'll get an absolute path, likely with your own home directory in it, which isn't so good if the project you're working on is shared with other people. To specify a working directory relative to the project folder in there, find the "Working Directory" field in the scheme (In XCode 10.1, that's Product | Scheme | Edit Scheme, then Options, then check "Use Custom Working Directory"), and use $PROJECT_DIRto get the path relative to the project.

当前此处的各种答案建议在通过编辑方案执行项目时设置工作目录,然后选择您想要的任何目录,但似乎缺少问题的关键部分:相对路径。如果您只是在 UI 中使用文件导航器,您将获得一个绝对路径,其中可能包含您自己的主目录,如果您正在处理的项目与其他人共享,则这不太好。要指定相对于其中的项目文件夹的工作目录,请在方案中找到“工作目录”字段(在 XCode 10.1 中,即产品 | 方案 | 编辑方案,然后是选项,然后选中“使用自定义工作目录”),然后使用$PROJECT_DIR获取相对于项目的路径。

回答by shodak

Using Xcode 9:

使用 Xcode 9:

It may be intended for Xcode to always use relative file paths based on the directory that contains the xcodeproj, but sometimes this does not seem to be true, and in my case this may have been due to the fact that the project (directory and all) was copied from an earlier version. I had to do:

Xcode 可能打算始终使用基于包含 xcodeproj 的目录的相对文件路径,但有时这似乎并非如此,在我的情况下,这可能是由于项目(目录和所有) 是从早期版本复制的。我必须做:

Target(top left)->Edit Scheme->Use Custom Working Directory

目标(左上)->编辑方案->使用自定义工作目录

and then specify to use the directory containing my project file.

然后指定使用包含我的项目文件的目录。