Bruno Haible wrote: > Peter O'Gorman wrote: >> crt_externs.h and _NSGetEnviron works on all released versions of Mac OS X. > > Thanks for this info. I'm updating the doc (see below). > >> 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. > > Well, there must be something different between MacOS X 10.[34] and 10.5. > The cited references mention a problem that cropped up with 10.5, not > earlier. > > Attached you find the test script that I used to verify that both declarations > work on 10.3. (I cannot test 10.4 or 10.5.)
It is an old problem, e.g. http://lists.apple.com/archives/Darwin-development/2003/Apr/msg00177.html Here is me compiling your test on Mac OS X 10.5 (using the systems GNU libtool 1.5.22): mb:environs peter$ cat fooshared.c #if 1 extern char **environ; #else #include <crt_externs.h> #define environ (*_NSGetEnviron()) #endif char *** environ_addr (void) { return &environ; } mb:environs peter$ glibtool --mode=compile gcc -c fooshared.c gcc -c fooshared.c -fno-common -DPIC -o .libs/fooshared.o gcc -c fooshared.c -o fooshared.o >/dev/null 2>&1 mb:environs peter$ glibtool --mode=link gcc -o libfoo.la fooshared.lo -rpath /no texist rm -fr .libs/libfoo.0.0.0.dylib .libs/libfoo.0.dylib .libs/libfoo.a .libs/libfo o.dylib .libs/libfoo.la .libs/libfoo.lai gcc -dynamiclib ${wl}-undefined ${wl}dynamic_lookup -o .libs/libfoo.0.0.0.dylib .libs/fooshared.o -install_name /notexist/libfoo.0.dylib -Wl,-compatibility_ version -Wl,1 -Wl,-current_version -Wl,1.0 (cd .libs && rm -f libfoo.0.dylib && ln -s libfoo.0.0.0.dylib libfoo.0.dylib) (cd .libs && rm -f libfoo.dylib && ln -s libfoo.0.0.0.dylib libfoo.dylib) ar cru .libs/libfoo.a fooshared.o ranlib .libs/libfoo.a creating libfoo.la (cd .libs && rm -f libfoo.la && ln -s ../libfoo.la libfoo.la) mb:environs peter$ glibtool --mode=link gcc -o libfoo.la fooshared.lo -rpath /no texist -no-undefined rm -fr .libs/libfoo.0.0.0.dylib .libs/libfoo.0.dylib .libs/libfoo.a .libs/libfo o.dylib .libs/libfoo.la .libs/libfoo.lai gcc -dynamiclib -o .libs/libfoo.0.0.0.dylib .libs/fooshared.o -install_name /notexist/libfoo.0.dylib -Wl,-compatibility_version -Wl,1 -Wl,-current_version -Wl,1.0 Undefined symbols: "_environ", referenced from: _environ$non_lazy_ptr in fooshared.o ld: symbol(s) not found collect2: ld returned 1 exit status Peter -- Peter O'Gorman http://pogma.com