You are not logged in.

#1 2010-03-17 12:35:30

Braven
Member
Registered: 2010-03-17
Posts: 3

How do executables find their data

I've been using linux for a few months now, but I have yet to figure out something that has been nagging at me the whole time: How do binaries find their associated data? Take a game, for instance. Where the binary is located in /usr/bin but the graphics and sound data are located in /usr/share. What exactly is the process that the system uses in order to connect the executable with the data its requesting?

Does the application have to request it directly, such as: openfile("/usr/share/game/sprite.png")?

Or if the application says openfile("spirte.png") to the operating system, does the operating system automatically look in the /usr/share/game directory for the data? If so, is there a config file somewhere to specify what that directory is if the distribution wants to use something other than /usr/share to store application data?

Offline

#2 2010-03-17 13:09:48

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: How do executables find their data

Typically it knows that the data is in a specific directory (share/progname/) and compiling it tells it where. ./compile --prefix=/usr (or /usr/local/). Then it looks in $prefix + share/progname/. It's not automatic, which is why some stuff gets put in /opt.

Offline

#3 2010-03-17 14:45:22

Braven
Member
Registered: 2010-03-17
Posts: 3

Re: How do executables find their data

Ah, I see. Is it usually the configure script that takes care of that, in most package, I assume? I believe I understand now, thank you.

Offline

#4 2010-03-17 16:09:17

fsckd
Forum Fellow
Registered: 2009-06-15
Posts: 4,173

Re: How do executables find their data

It's usually hard coded into the binary and is set at compile time when configuring the package. Usually if you read a man page, it will state something along the lines of, "will search for files in these directories in the list order" followed by a list of directories.


aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies

Offline

#5 2010-03-18 14:39:46

jimburnettva
Member
From: Virginia, USA
Registered: 2010-02-12
Posts: 48
Website

Re: How do executables find their data

Keep in mind that most distributions tweaked source code for their own distributions to keep stuff streamlined. For example an author may hardcode a path in their software but Ubuntu/Arch or whoever may tweak that code to use a more standard form. Most of the time environment variables and prefixes are use as stated above.

Normally /usr/share/appname is used.  (What Daenyth said  :0-)   )


My Linux & Progamming Blog - Jimmy Burnett

Offline

#6 2010-03-18 16:18:31

Bralkein
Member
Registered: 2004-10-26
Posts: 354

Re: How do executables find their data

Yeah this is the kind of thing where as a programmer you really feel like you shouldn't be having to do it, but at the same time there isn't an easy solution which would work everywhere. You just want to say "give me my data! Find it! Find it now!" and have some lackey-function magically retrieve what you need, but alas... smile

The harsh reality of the situation is that programming really can be this boring!

Offline

Board footer

Powered by FluxBB