如何指定 XCode 存储编译后的二进制文件的位置?

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

How do I specify where XCode stores the compiled binaries?

xcodebinary-data

提问by limp_chimp

I'm writing in C++11 and for some reason, I haven't been able to get gcc to compile it, so I've been using XCode. However, I'm writing programs that take arguments from the command line, so I need to be able to run them from the shell. Right now, XCode is burying the binaries it compiles in a deep and inconvenient location (/Users/username/Library/Developer/XCode/DerivedData/ProjectName/Build/Products/Debug/... yikes!). I'd like to be able to specify a better location for them, and possibly another name as well. I'm using XCode 4.5.2. Can anyone help me out with this?

我正在用 C++11 编写,出于某种原因,我无法让 gcc 编译它,所以我一直在使用 XCode。但是,我正在编写从命令行获取参数的程序,因此我需要能够从 shell 运行它们。现在,XCode 正在将它编译的二进制文件埋在一个很深且不方便的位置(/Users/username/Library/Developer/XCode/DerivedData/ProjectName/Build/Products/Debug/... yikes!)。我希望能够为他们指定一个更好的位置,可能还有另一个名字。我正在使用 XCode 4.5.2。谁能帮我解决这个问题?

回答by Mecki

You can configure this once globally for all projects in the Xcode preferences:

您可以在 Xcode 首选项中为所有项目全局配置一次:

"Xcode" Menu -> "Preferences..." -> "Locations" Tab -> "Advanced..." Button

“Xcode”菜单->“首选项...”->“位置”选项卡->“高级...”按钮

Or you can change it per project. Just open a project, select one of the project windows and then:

或者您可以按项目更改它。只需打开一个项目,选择一个项目窗口,然后:

"File" Menu -> "Project Settings..." -> "Advanced..."

“文件”菜单->“项目设置...”->“高级...”

Unless otherwise configured, new projects use the defaults you have configured in the global Xcode prefs, but you may want to override them for individual projects.

除非另有配置,新项目使用您在全局 Xcode 首选项中配置的默认值,但您可能希望为单个项目覆盖它们。

Note that if you select "Legacy", Xcode will place them by default into the folder where the Xcode itself is located, but "Legacy" also allows you to specify the location using build settings, thus you can even set different locations per target. The project settings are named Build Products Pathand Intermediate Build Files Path. If you are not in "Legacy" mode (either by setting it on the project or globally for all projects), these two build settings have no effect and are entirely ignored.

请注意,如果您选择“Legacy”,Xcode 将默认将它们放置到 Xcode 本身所在的文件夹中,但“Legacy”还允许您使用构建设置指定位置,因此您甚至可以为每个目标设置不同的位置。项目设置被命名为Build Products PathIntermediate Build Files Path。如果您未处于“传统”模式(通过在项目上设置或为所有项目全局设置),则这两个构建设置将无效并被完全忽略。

Also note that when you build Xcode projects on command line using xcodebuild, they are always built in legacy mode, regardless what you configured in Xcode or in the project settings. This is useful, since it allows you to override the output location from command line by overriding the two projects settings I mentioned above. This can be either done in a xcconfigfile, just tell xcodebuildto read config from such a file (-xcconfig <filename>) or it can be done directly on the command line by adding <setting>=<value>as an argument at the end of the xcodebuildcall. When specified in a xcconfigfile or via command line, the two settings are named SYMROOT(=Build Products Path) and OBJROOT(=Intermediate Build Files Path).

另请注意,当您在命令行上使用 构建 Xcode 项目时xcodebuild,它们始终以传统模式构建,无论您在 Xcode 或项目设置中配置了什么。这很有用,因为它允许您通过覆盖我上面提到的两个项目设置来覆盖命令行的输出位置。这可以在xcconfig文件中完成,只需告诉xcodebuild从这样的文件 ( -xcconfig <filename>)读取配置,或者可以通过<setting>=<value>xcodebuild调用末尾添加参数直接在命令行上完成。当在xcconfig文件中或通过命令行指定时,这两个设置被命名为SYMROOT(= Build Products Path) 和OBJROOT(= Intermediate Build Files Path)。

回答by trojanfoe

You can specify the location in Preferences -> Locations. I use ~/tmp:

您可以在首选项 -> 位置中指定位置。我使用~/tmp

enter image description here

在此处输入图片说明

回答by trojanfoe

Alternatively in Xcode you could go to "Build Phases", and "Add a new build phase", selecting "New Run Script Phase". Then simply add a script similar to cp /path/to/build/products/productname /path/to/where/you/want/to/copy/newproductname. The cpis the command line copycommand. This is nice, clean way to put your build product where you want.

或者,在 Xcode 中,您可以转到“构建阶段”和“添加新构建阶段”,选择“新建运行脚本阶段”。然后只需添加一个类似于cp /path/to/build/products/productname /path/to/where/you/want/to/copy/newproductname. 该cp是命令行复制命令。这是将构建产品放置在所需位置的好方法。