Bruno Haible wrote: > > 2008-02-24 Bruno Haible <[EMAIL PROTECTED]> > > * doc/posix-functions/environ.texi: Document the MacOS X problem. > > *** doc/posix-functions/environ.texi.orig 2008-02-24 15:26:50.000000000 > +0100 > --- doc/posix-functions/environ.texi 2008-02-24 15:25:16.000000000 +0100 > *************** > *** 16,21 **** > --- 16,33 ---- > This variable is missing on some platforms: > MacOS X 10.3, FreeBSD 6.0, NetBSD 3.0, OpenBSD 3.8, IRIX 6.5, OSF/1 5.1, > Cygwin. > @item > + On MacOS X 10, this variable is not declared. Up to MacOS X 10.4, one can > use > + @smallexample > + extern char **environ; > + @end smallexample > + to get the variable declared. This does not work any more, however, in > + shared libraries on MacOS X 10.5. Here is a workaround: Instead, one can > use > + @smallexample > + #include <crt_externs.h> > + #define environ (*_NSGetEnviron()) > + @end smallexample > + This works at least on MacOS X 10.3 and newer.
Hi Bruno, crt_externs.h and _NSGetEnviron works on all released versions of Mac OS X. The environ symbol is available to every application, it is in the c startup object crt1.o (on 10.5 crt1.10.5.o), but the static linker, when set to not allow any undefined symbols (the default) does not know about it when creating a shared library (because crt1.0 is only added when creating an executable), so linking will fail with undefined references to _environ in that case. A library which allows undefined symbols (the GNU libtool default) will not see this problem. Thanks for writing this up, it is good to have the crt_externs.h solution in the docs. Peter -- Peter O'Gorman http://pogma.com