How do I use a relative path in Xcode project settings?

XcodePathRelative Path

Xcode Problem Overview


How do I use a relative path in Xcode project settings?

Xcode Solutions


Solution 1 - Xcode

All paths in Build Settings are assumed relative to the directory that contains the .xcodeproj file. Use the standard Unix path tokens

.   project directory
..  parent directory

So if your project file is trunk/Mac/proj.xcodeproj, and your headers are in trunk/Headers/foo.h, you would add ../Headers to your Header Search Paths.

Solution 2 - Xcode

Also there are two paths: $SRCROOT and $SDKROOT.

Solution 3 - Xcode

In the upper left corner next to the build/stop buttons, click on the name of your project and Edit Scheme...

In the left column, click on Run

Click on Options

Put a check next to Working Directory: Use custom working directory.

You can then change the relative path to anywhere you want.

EDIT: This is for Xcode 4.1

Solution 4 - Xcode

For Xcode 5:

Click on Product -> Scheme -> Edit Scheme.

Then follow ulu5's instructions: Click "Run", Click on "Options", and check the box "Use custom working directory."

Solution 5 - Xcode

The various answers currently here which recommend setting the working directory when executing a project by editing the scheme and then choosing whatever directory you want are missing what seems like a key part of the question: Relative Path. If you just use the file navigator in the UI you'll get an absolute path, likely with your own home directory in it, which isn't so good if the project you're working on is shared with other people. To specify a working directory relative to the project folder in there, find the "Working Directory" field in the scheme (In XCode 10.1, that's Product | Scheme | Edit Scheme, then Options, then check "Use Custom Working Directory"), and use $PROJECT_DIR to get the path relative to the project.

Solution 6 - Xcode

Using Xcode 9:

It may be intended for Xcode to always use relative file paths based on the directory that contains the xcodeproj, but sometimes this does not seem to be true, and in my case this may have been due to the fact that the project (directory and all) was copied from an earlier version. I had to do:

Target(top left)->Edit Scheme->Use Custom Working Directory

and then specify to use the directory containing my project file.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionShayView Question on Stackoverflow
Solution 1 - XcodecdespinosaView Answer on Stackoverflow
Solution 2 - XcodeMike ChenView Answer on Stackoverflow
Solution 3 - Xcodeulu5View Answer on Stackoverflow
Solution 4 - Xcodeuser3483663View Answer on Stackoverflow
Solution 5 - Xcodeorion elenzilView Answer on Stackoverflow
Solution 6 - XcodeshodakView Answer on Stackoverflow