[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: environ on MacOS X

From: Peter O'Gorman
Subject: Re: environ on MacOS X
Date: Sun, 24 Feb 2008 10:43:50 -0600
User-agent: Thunderbird (X11/20071115)

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.

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;
#include <crt_externs.h>
#define environ (*_NSGetEnviron())
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
rm -fr  .libs/libfoo.0.0.0.dylib .libs/libfoo.0.dylib .libs/libfoo.a
o.dylib .libs/libfoo.la .libs/libfoo.lai
gcc -dynamiclib ${wl}-undefined ${wl}dynamic_lookup -o
 .libs/fooshared.o   -install_name  /notexist/libfoo.0.dylib
version -Wl,1 -Wl,-current_version -Wl,1.0
(cd .libs && rm -f libfoo.0.dylib && ln -s libfoo.0.0.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
o.dylib .libs/libfoo.la .libs/libfoo.lai
gcc -dynamiclib  -o .libs/libfoo.0.0.0.dylib  .libs/fooshared.o
 /notexist/libfoo.0.dylib -Wl,-compatibility_version -Wl,1
Undefined symbols:
  "_environ", referenced from:
      _environ$non_lazy_ptr in fooshared.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

Peter O'Gorman

reply via email to

[Prev in Thread] Current Thread [Next in Thread]