Jump to content
  • Advertisement
Sign in to follow this  
MARS_999

Boost and path to the app dir?

This topic is 3348 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to find the path to the app under OSX with boost. I this so far path my_path( "some_dir/file.txt" ); but that assumes I know that path. I need to find the path to the file correct? SO how does one do that? Thanks

Share this post


Link to post
Share on other sites
Advertisement
I'd suggest examining the command line instead. The first parameter on the command line ( argv[0] ) should be the path to the program.

At least under Windows this can be different to the current working directory.

Share this post


Link to post
Share on other sites
Quote:
Original post by Adam_42
I'd suggest examining the command line instead. The first parameter on the command line ( argv[0] ) should be the path to the program.

At least under Windows this can be different to the current working directory.


This is a better idea...however I think the argv[0] is actually what was used to invoke the process? So you could end up just having the executable name, if the current directory==executable directory, or if the executable directory is part of the PATH env variable and the user just typed c:\>MyExecutable.exe for example. Does anyone know if it's ever possible for this to not even contain the filename, for example if the process was spawned from another?

I think what you really want is a boost::filesystem (read cross platform) version of the Win32 function GetModuleFilename. Looking in the boost docs it doesn't look like there is anything that fits the bill...

Perhaps you could look at the OSX api and see if there is something similar? If you are aiming for total cross platform, then I'm afraid I don't know of anything, but you could perhaps implement your own cross platform abstraction.

Share this post


Link to post
Share on other sites
According to my experience with Linux and Windows the argv[0] only has what the user gave to it in the command line.

So it is pretty much useless if you want to know the full path to the executable.

I do not know OSX but I would be surprised if the behaviour is that much different there.

Share this post


Link to post
Share on other sites
In Cocoa you would obtain the path with [[NSBundle mainBundle] bundlePath]. You can use Objective-C++ to access Cocoa from a C++ application, so that might be your best bet.

Share this post


Link to post
Share on other sites
That's funny, I asked pretty much this same question on StackOverflow the other day. Here's a link with some useful information. The short of it is that there's no cross-platform way to do it, which frankly sounds ridiculous to me!

http://stackoverflow.com/questions/1528298/get-path-of-executable

Share this post


Link to post
Share on other sites
Quote:
Original post by hymerman
That's funny, I asked pretty much this same question on StackOverflow the other day. Here's a link with some useful information. The short of it is that there's no cross-platform way to do it, which frankly sounds ridiculous to me!

http://stackoverflow.com/questions/1528298/get-path-of-executable
I went back and forth over this with SiCrane a few months back. IIRC, the upshot is that most platforms give you a path in argv[0] which is sufficient to exec() the current process.

There are unfortunately two problems with this: a) even when you get a working path, it tends to be relative to the PATH environment variable, and b) cygwin only hands you the executable name, no matter what you do.

Share this post


Link to post
Share on other sites
Sigh, issues with coding x platform and no good way to do it... I will take a look at maybe doing a preprocessor #ifdef statement or something to setup the system I am coding for and use the local API I guess. I was hoping BOOST would help since its supposed to be a C++ coders dream toolbox from what I hear.

Anyway thanks all for the info.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!