Skip navigation.
 
mlRe: Finding out executable location from a c program
FROM : Antti Karanta
DATE : Fri Nov 23 21:52:46 2007

On Tue, 20 Nov 2007 14:36:53 +0200, Alastair Houghton 
<<email_removed>> 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-

Related mailsAuthorDate
mlFinding out executable location from a c program Antti Karanta Nov 19, 17:06
mlRe: Finding out executable location from a c program I. Savant Nov 19, 17:12
mlRe: Finding out executable location from a c program Antti Karanta Nov 19, 17:24
mlRe: Finding out executable location from a c program Paul Sargent Nov 19, 17:37
mlRe: Finding out executable location from a c program I. Savant Nov 19, 17:44
mlRe: Finding out executable location from a c program Christiaan Hofman Nov 19, 17:51
mlRe: Finding out executable location from a c program Roy Lovejoy Nov 19, 23:53
mlRe: Finding out executable location from a c program Scott Stevenson Nov 19, 23:55
mlRe: Finding out executable location from a c program Clark Cox Nov 20, 03:09
mlRe: Finding out executable location from a c program Scott Stevenson Nov 20, 06:31
mlRe: Finding out executable location from a c program Clark S. Cox III Nov 20, 06:37
mlRe: Finding out executable location from a c program Alastair Houghton Nov 20, 13:36
mlRe: Finding out executable location from a c program Antti Karanta Nov 23, 21:22
mlRe: Finding out executable location from a c program Antti Karanta Nov 23, 21:52
mlRe: Finding out executable location from a c program Douglas Davidson Nov 26, 19:44
mlRe: Finding out executable location from a c program Alastair Houghton Nov 27, 13:11