Search code examples
macospathpwd

What is the `pwd` of a Mac bundled app?


I'm running a GLFW app (that I wrote in C++)

I run it as follows:

./prog.app/Contents/MacOS/prog # from the command line

However, my code can't read relative-pathed files properly.

So I believe what's happening is that this Mac Bundle is changing my current directory.

1) what does it change it to? 2) can I control this?

Thanks!


Solution

  • Never make any assumptions about the current working directory when your app is launched. The Finder is reasonably consistent about this but it is not the only way to launch an app. When debugging under Xcode for example the initial working directory will be different, and there are various other methods which may or may not set the working directory as expected. You should test your app by launching it from the command line in a totally unrelated directory - if it still finds its files under this condition then you're in good shape.