Finding out executable location from a c program
Antti Karanta
antti.karanta at napa.fi
Fri Nov 23 12:52:46 PST 2007
On Tue, 20 Nov 2007 14:36:53 +0200, Alastair Houghton
<alastair at alastairs-place.net> wrote:
> You can use _NSGetExecutablePath() from <mach-o/dyld.h>.
I didn't try this as using cfbundle as proposed by another poster did
the trick. Thanks anyway.
> It's perhaps worth saying though that using the path of your tool is
> generally an evil thing to do.
Why is it evil?
Perhaps I should explain a little background on what I am doing and why
I'm doing it the way I am. I am open to suggestions and corrections, of
course. I admit being quite unfamiliar w/ os-x, as on my payjob I work on
windows and at home use linux (due to having gotten the x86 hardware dirt
cheap - if I had to pay the normal price I would have gone for apple
having heard so much praise for it ; ).
I am developing a small c program to launch groovy scripts (see
groovy.codehaus.org). The launcher used at the moment is a shell script
(bash script I believe) that relies on environment variable GROOVY_HOME to
be set to find the resources needed to start groovy runtime (java jars
containing the actual program + a conf file). My native launcher does not
depend on that environment variable to be set.
The c-launcher I've written
(http://docs.codehaus.org/display/GROOVY/Native+Launcher) is
multi-platform, sticking to ansi-c and posix functions as much as possible
for maximum portability. Currently it works on windows, linux, os-x and
solaris.
Groovy is written in Java and the distribution is the same (files) for
all platforms (except for my native launcher, which atm is only included
on windows installer by default). Thus my launcher can rely on finding the
resources needed for startup in the same location relative to the
distribution root. The distribution root, in turn, can be deduced from the
location of the executable.
I'm not in control of how groovy distribution is laid out, but even if I
was I can not see what would be the benefit of separating the launcher
executable and the rest of the distribution (into "normal UNIX places")
versus keeping the distribution file layout the same on all platforms.
-Antti-
More information about the MacOSX-dev
mailing list