Xcode:如何将当前工作目录设置为可执行文件的相对路径?

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

Xcode: How to set current working directory to a relative path for an executable?

xcodexcode5

提问by izak

I have a command-line executable in Xcode.

我在 Xcode 中有一个命令行可执行文件。

I am using Xcode 5.1. In the "Scheme Editor" for the project under "Options" there is an option for "Working Directory". How can I specify a path relative to the .xcodeproj file? I have tried a single period.

我正在使用 Xcode 5.1。在“选项”下项目的“方案编辑器”中,有一个“工作目录”选项。如何指定相对于 .xcodeproj 文件的路径?我试过一个时期。

I need this because the code needs to assume the existence of files relative to the project directory.

我需要这个是因为代码需要假设存在相对于项目目录的文件。

回答by Paul R

You can use Xcode build setting variablessuch as PROJECT_DIR, e.g. setting your working directory to $PROJECT_DIR/..will make it equal to the parent directory of your project directory.

您可以使用Xcode的构建环境变量,例如PROJECT_DIR,例如,您的工作目录设置为$PROJECT_DIR/..将使它等于你的项目目录的父目录。

回答by Mike Akers

In Xcode preferences you can change the location of the compiled binaries to be relative to your project, or at any absolute path you like. Go to Preferences->Locationsand then click on the Advanced...button below the Derived Datatext field.

在 Xcode 首选项中,您可以将编译后的二进制文件的位置更改为相对于您的项目,或者您喜欢的任何绝对路径。转到Preferences->Locations然后单击文本字段Advanced...下方的按钮Derived Data

In the sheet that pops up set the Build Locationto Custom, and then select the desired option in the nearby dropdown, and enter whatever paths you like in the Productsfield.

在弹出的工作表中,将 设置Build LocationCustom,然后在附近的下拉列表中选择所需的选项,并在该Products字段中输入您喜欢的任何路径。

Screenshot of Xcode Derived Data location diaglog

Xcode 派生数据位置对话框的屏幕截图