views:

207

answers:

2

I am creating a C++ SDL game engine, and it is relevant to know the executable path since images and other resources are not stored within the executable - they are in a separated folder("res/").

Under Linux, I am using a shell script "rungame.sh" that cd's to the executable path and then runs the executable(using then "./" to reference the executable folder). However, I believe this is an "ugly" approach and I want it to be Windows-compatible.

Also, the current approach is not very good as it may change the meaning of some command line arguments.

I want a cross-platform(*NIX, Windows and Mac OS X, if possible) solution to get the current path of the executable. The game path/executable name may change.

What is the cleanest way to solve my problem (preferrably using std::string and as few platform-dependent APIs as possible)?

+1  A: 

I strongly suggest searching before posting: http://stackoverflow.com/questions/143174/c-c-how-to-obtain-the-full-path-of-current-directory

Jacek Ławrynowicz
Actually, it is not the solution I needed. That is about getting the current directory path. I want the EXECUTABLE directory path.If I run 'cd /something/' then run './x/y', that will output '/something/' and I want it to output '/something/x/'.
luiscubal
It turns out it had that answer too. However, it wasn't the question so I guess I couldn't discover it using StackOverflow's search system.
luiscubal
A: 

I think physicsfs has some cross-platform code to do this.

genpfault