473,395 Members | 1,756 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Where to find files at runtime?

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?

Thanks!

Jul 22 '05 #1
2 1341
On Fri, 14 Jan 2005 04:59:03 -0500, Markus Dehmann <ma*******@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
Jul 22 '05 #2
Markus Dehmann 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?


Write a function that returns the directory and declare only that function
in the header. This way, the header won't change and you only have to
recompile the impmementation file for that short function. Another thing
you could do is to let the program search for a configuration file in /etc
or $HOME and then read the directory from that file. You could also make
the directory configurable through a command line parameter.
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Gert Schumann | last post by:
I'm operating on sun OS 5.6 I ping a host every 10 seconds to get knowlegde wheather it is running or not. After about one and a half hour I get this Exception: java.io.IOException: Too many open...
1
by: eBob.com | last post by:
Well I am now on page 84 of Bruce Eckel's "Thinking in Java". (... having made significant progress since the help you guys gave me in response to my last question about page 34.) Here he...
0
by: Sijmen | last post by:
In reference to the following post by Brandon Bray from Microsoft: http://groups.google.com/groups?q=g:thl1709599354d&dq=&hl=en&lr=&ie=UTF-8&selm=%238CXKwM3BHA.2488%40tkmsftngp04 Among other...
2
by: Mark D. Richter | last post by:
These are two merge modules for the C runtime. Is there a "legit" place that Microsoft makes these available? MSDN? (Searching MSDN was not very fruitful however.) I am building in the VS 7.1...
11
by: Kenneth P | last post by:
Hi, This link works but when you try to download IE WebControls you'll get to page that doesn't exist. http://msdn.microsoft.com/workshop/webcontrols/overview/overview.asp Anyone who could...
2
by: Benton | last post by:
Hi there, Maybe a dumb question but I am playing with VWD 2005 Beta 1 (using the integrated web server) and wonder where is the binary file of the compiled project. I can't find it on the...
3
by: Saman | last post by:
I have a third party dll and I am sure that it is not an activeX or dotnet assembly . I have check it up with Dependency Walker software and found the list of it's exported function in C++ syntax...
2
by: graphicsxp | last post by:
Hi, How can I open all the files in a directory, which names match a particular string ? Say I have a string like 'a file name to find' and I want to find and open all the files of a given...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.