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

Discussion in 'C++' started by mathieu, Jun 28, 2008.

  1. mathieu

    mathieu Guest

    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
    mathieu, Jun 28, 2008
    #1
    1. Advertising

  2. mathieu

    Guest

    Re: Handling external ressource (aka How can I find a process'executable file)

    On Jun 28, 8:39 am, mathieu <> wrote:
    > 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
    , Jun 28, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Patrick

    default ressource

    Patrick, Nov 25, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    289
    Patrick
    Nov 25, 2003
  2. Steve B.
    Replies:
    0
    Views:
    627
    Steve B.
    Feb 26, 2004
  3. Olivier Matrot

    Are satellite assemblies only for ressource ?

    Olivier Matrot, Apr 15, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    415
    Patrice
    Apr 15, 2005
  4. Jéjé
    Replies:
    0
    Views:
    353
    Jéjé
    May 25, 2005
  5. Fh
    Replies:
    0
    Views:
    331
Loading...

Share This Page