473,804 Members | 2,034 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1361
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
12156
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 files at java.lang.UNIXProcess.forkAndExec(Native Method) at java.lang.UNIXProcess.<init>(UNIXProcess.java:54) at java.lang.Runtime.execInternal(Native Method) at java.lang.Runtime.exec(Runtime.java:546) at...
1
2032
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 presents a simple program which uses two classes, System and Runtime. And he suggests using packages.html to find those two classes. He says "If you look at the packages.html file, you'll see a list of all the different class libraries that come with...
0
12634
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 things, the thread talks about the C Runtime files such as MSVCR71.DLL, and seems to indicate that they should be installed in our applications directory, and not in the System32 directory. Specifically, Brandon states the following about installing...
2
4310
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 environment (C#) with a 3rd party merge module that depends on VC_USR.msm and VC_STL.msm. Many thanks. Mark Richter
11
7946
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 help me get the IE WebControls download link? TIA
2
1047
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 project's source directory as there is no 'bin' folder in there. Where can I find it? I need to move it to another computer with IIS to do some testing. Thanks in advance,
3
15512
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 for example : void __cdecl TelEnd(void) void __cdecl FaxStop(void) and so on ...
2
2268
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 directory, which name contains that string. Here is how I open the file of a directory. How can it be modified to
0
9711
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10594
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10331
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9166
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7631
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5529
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5667
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4306
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.