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

6

72

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

Faunia answered 13/9, 2009 at 5:30 Comment(1)
For this decade old question! A weird issue seems to have come up in Xcode 11 ... #58955343Waldrop
S
103

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.

Sorayasorb answered 13/9, 2009 at 6:16 Comment(2)
what about libraries? can I have my .a files outside the project and add their path relatively to the project?Dawdle
Yes, see here chilkatsoft.com/xcode-link-static-lib.asp. Adding it this way will make sure the linker gets passed the -lmylib flag. Then add the path to this library in Build Settings->Search Paths->Library Search PathsMichamichael
F
43

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

Fulmar answered 13/9, 2009 at 10:13 Comment(1)
using 2 dots, i.e: "../someFolder" will give you your workspace folder while $SRCROOT will only gives you the project folder (which could be inside the workspace folder).Acetous
F
7

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

Fibriform answered 7/4, 2012 at 6:7 Comment(4)
in the Run Options , there is only 2 options: Core Location & Application Data. No Working Directory. xCode 4.3Chalcidice
In xCode 4.5 this option is in Product>Edit Scheme ..... This worked for me, thanks.Trehalose
i second @ShivanRaptor.. there is no working directory in xCode 4.5Receiver
i reopened this issue hereReceiver
S
4

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

Succussion answered 1/4, 2014 at 5:7 Comment(0)
P
3

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.

Protagoras answered 10/12, 2018 at 17:32 Comment(1)
wups just saw your comment, @Waldrop . that link is 404 now, unfortunately.Protagoras
M
0

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.

Manual answered 20/10, 2018 at 8:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.