0

I compile using eclipse and c++11 under both Windows and OSX. When I create a release and drag it to another folder, the Windows binary has the current current working directory. The OSX release thinks it's in my home folder. No matter where I place it, it thinks it is running in my home directory.

I put a print statement in my code to prove it: Current working dir: /Users/Dom

This problem only occurs if I double click the binary. If I open a terminal and run the program using ./ it opens in the proper directory.

I'm not sure how to fix this, but it needs to be fixed in order for the application to find relative path specific resources.

Thanks!

SOLUTION:

char path[1024];
uint32_t size = sizeof(path);
if (_NSGetExecutablePath(path, &size) == 0){ /*...*/ }
DCurro
  • 1,797
  • 1
  • 15
  • 16

1 Answers1

1

It won't work under Windows if you're UAC-elevated either, as the current directory is reset to %WINDIR%\system32 during the elevation. All processes [on these platforms] have the concept of a current directory which is NOT guaranteed to be the program's directory. You'll likely need to find your binary in another way, such as one of these ways: https://stackoverflow.com/a/1024937/2101267

Community
  • 1
  • 1
Dark Falcon
  • 43,592
  • 5
  • 83
  • 98