20

I managed to get my C++ project running in Xcode using cmake -G Xcode. Now I would like to debug it, because of the nice gdb fronted it provides.

However I need to change the working directory where gdb is executed otherwise it wont work. (It needs to read some data from files relative to the path of the working directory) What I can do is after gdb has stopped typing cd working_dir and then run it manually typing r. This works, but Xcode will complain constantly and is also not an elegant solution.

So somewhere in the build settings I should be able to set the working directory..but where?!

Nils
  • 13,319
  • 19
  • 86
  • 108
  • 1
    Nils: Please make the answer by gibertoni the accepted one. I spent some unnecessary minutes until I noticed that Paul's answer applies to a long-outdated version of Xcode. – fieres May 07 '21 at 07:45

4 Answers4

51

Just updating this solution to XCode 4.x

You go on Product -> Scheme -> Edit Scheme

On the tab Options you choose your working directory.

gibertoni
  • 1,368
  • 12
  • 21
  • 3
    This option is no longer available at this place in XCode 4.6.1 – Alexis Mar 19 '13 at 10:41
  • i cannot see working directory option in xcode 5, can you guide where it is – Iqbal Khan Sep 23 '13 at 06:02
  • @Developer I have just updated to 5.0 and the option is still in the same path for me. – gibertoni Sep 24 '13 at 22:23
  • 1
    @Developer This problem occurs when dealing with an iOS project. I couldn't find the option either. When I find it, I will update my answer on this topic. – gibertoni Oct 12 '13 at 17:09
  • XCode (i'm on v7.3.1) ignores the "Use custom working directory" setting if you debug as root. It always sets the working dir to "/" – Matt Cobb Sep 09 '16 at 00:48
13

In Xcode 4 the working directory settings is under Scheme Settings.

avee
  • 766
  • 1
  • 13
  • 22
4

In Xcode 3.x do a "Get Info" on the executable and look at the first tab - there is a setting there for working directory.

Paul R
  • 208,748
  • 37
  • 389
  • 560
  • How could I oversee that? I was looking at the target properties.. thanks! – Nils Aug 03 '10 at 13:36
  • No problem - it's easy to get mixed up between the target settings and the executable settings - I do this all the time and I've been using Xcode for *years*. – Paul R Aug 03 '10 at 13:54
  • 3
    Total XCode newbie here - How exactly do I "do a GetInfo on the executable" ? The scheme has a working dir option, but my fopen() still fails. I have XCode 4.2 if that matters. – Calvin1602 Oct 12 '12 at 09:50
  • @Calvin1602: the answer above applies to Xcode 3.x and before (it's from 2010) - Xcode 4 is quite different - there's a newer answer from KuramaYoko below which applies to Xcode 4.x. – Paul R Oct 12 '12 at 12:43
2

The default debug working directory is somewhere under ~/Library/Developer/Xcode/DerivedData/project-/Build/Products/Debug. You're better off using the full path.

Dave Mooney
  • 783
  • 9
  • 25