How do I specify where XCode stores the compiled binaries?

How do I specify where XCode stores the compiled binaries?

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?


Answer 1:

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

Answer 2:

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

enter image description here

Answer 3:

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.