How do I specify where Xcode stores the compiled binaries?
Asked Answered
L

3

6

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.

Laliberte answered 20/1, 2013 at 20:11 Comment(2)
possible duplicate of XCode 4 - build output directoryDuran
it is indeed. Sorry about that, but thanks. This can be closed, then.Laliberte
G
9

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).

German answered 21/1, 2013 at 0:36 Comment(0)
J
2

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

enter image description here

Joselow answered 20/1, 2013 at 23:24 Comment(0)
B
1

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 cp is the command line copy command. This is nice, clean way to put your build product where you want.

Brewington answered 3/1, 2016 at 1:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.