我正在用 C++11 编写,由于某种原因,我无法让 gcc 编译它,所以我一直在使用 XCode。但是,我正在编写从命令行获取参数的程序,因此我需要能够从 shell 运行它们。现在,XCode 正在将它编译的二进制文件埋在一个很深且不方便的位置(/Users/username/Library/Developer/XCode/DerivedData/ProjectName/Build/Products/Debug/...哎呀!)。我希望能够为他们指定一个更好的位置,并且可能还有另一个名字。我正在使用 XCode 4.5.2。谁能帮我解决这个问题?
3 回答
You can configure this once globally for all projects in the Xcode preferences:
"Xcode" Menu -> "Preferences..." -> "Locations" Tab -> "Advanced..." Button
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.
Note that if you select "Legacy", Xcode will place them by default into the folder where the Xcode project 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 Path
and 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.
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 xcconfig
file, just tell xcodebuild
to 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 xcodebuild
call. When specified in a xcconfig
file or via command line, the two settings are named SYMROOT
(=Build Products Path
) and OBJROOT
(=Intermediate Build Files Path
).
您可以在 Preferences -> Locations 中指定位置。我使用~/tmp
:
或者在 Xcode 中,您可以转到“构建阶段”和“添加新的构建阶段”,选择“新运行脚本阶段”。然后只需添加一个类似于cp /path/to/build/products/productname /path/to/where/you/want/to/copy/newproductname
. 是cp
命令行复制命令。这是将构建产品放置在您想要的位置的好方法。