Handling external ressource (aka How can I find a process' executablefile)

M

mathieu

Hi,

This is slightly off-topic (not purely C++). But I was wondering how
do people handle ressources (input file) in their C++ applications in
a cross platform way ?
I tought first of using relative path from the current running
executable, but I could not find a portable way of doing other than
getcwd/_getcwd + argv[0] which may or may not always work.

My current implementation is to produce a C++ file that gets
compiled during the build:

http://gdcm.svn.sourceforge.net/vie...taDictionary/gdcmDefaultDicts.cxx?view=markup



Thanks for suggestions !
-Mathieu
 
A

AnonMail2005

Hi,

  This is slightly off-topic (not purely C++). But I was wondering how
do people handle ressources (input file) in their C++ applications in
a cross platform way ?
  I tought first of using relative path from the current running
executable, but I could not find a portable way of doing other than
getcwd/_getcwd + argv[0] which may or may not always work.

  My current implementation is to produce a C++ file that gets
compiled during the build:

http://gdcm.svn.sourceforge.net/viewvc/gdcm/trunk/Source/DataDictiona...

Thanks for suggestions !
-Mathieu
In the systems I've done, code in core libraries use fully qualified
path names and it's the job of the application to supply those names
to the libraries.

For apps, you can easily use environment variables which specify the
full path name or the path excluding the filename. If I'm not
mistaken
getenv is part of the C library which makes it cross platform.

But I found that sprinkling getenv calls around code can lead to a
maintenance headaches so what I did was put everything in a config
file
and have the app take the config file name as it's only command line
arg.

The config file is just name/value pairs and can be any format you
like. But the key point is that I allow values inside the config
file to be specified using environment variables. Inside my cofig
file processing I expand the environment variables myself.

This approach has the benefit of environment variables but has
everything
centralized in one place - the config file.

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,233
Latest member
AlyssaCrai

Latest Threads

Top