Re: Where to find files at runtime?

From: Ulrich Achleitner (uac.medint_at_aon.at)
Date: 01/14/05


Date: Fri, 14 Jan 2005 11:10:52 +0100

On Fri, 14 Jan 2005 04:59:03 -0500, Markus Dehmann <markus.cl@gmx.de>
wrote:

> My app reads some text files at runtime. The problem is where to find
> them.
> In my project, we agreed to rather not define own environment variables.
>
> But then, it's hard to know at runtime where the files are because that
> changes with a "make install".
>
> I kind of solved this by letting the Makefile generate a header file that
> contains string variables with path information. The Makefile writes the
> values into that header file. The only downside is that most sources have
> to be recompiled for a "make install", because the header file changes
> with
> updated values like "/usr/local/..." instead of "/home/...".
>
> It's not really a good solution. How would you do that?

since the location of the executable may be anywhere, a solution is to
refer to your text files only by relative path with respect to the
location of the executable. this directory can (at least afaik) be found
in *argv[0] (from "main(argv, argc)")

should you then distribute your program, the setup must be so that the
text files go to the same realtive location with respect to the executable
then before. the simplest case of such a setup would be a zip-archive with
folder information.

-- 
have a nice day
ulrich


Relevant Pages


Loading