470,821 Members | 1,959 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,821 developers. It's quick & easy.

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

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/view...xx?view=markup

Thanks for suggestions !
-Mathieu
Jun 28 '08 #1
1 1213
On Jun 28, 8:39*am, mathieu <mathieu.malate...@gmail.comwrote:
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/view...e/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
Jun 28 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by Ritz, Bruno | last post: by
12 posts views Thread by Christian Christmann | last post: by
reply views Thread by Jéjé | last post: by
reply views Thread by calderara serge | last post: by
35 posts views Thread by jeffc226 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.