GNOME Bugzilla – Bug 313731
Undefined _environ symbol
Last modified: 2005-10-19 18:37:58 UTC
Please describe the problem: Linking against glib-2.8.0 on OS X fails because of an undefined _environ symbol. Steps to reproduce: 1. compile glib 2. compile pango or orbit Actual results: No errors during #1. Crash during #2 with: gcc -dynamiclib -o .libs/libpango-1.0.0.1000.0.dylib .libs/break.o .libs/ellipsize.o .libs/fonts.o .libs/glyphstring.o .libs/mapping.o .libs/modules.o .libs/pango-attributes.o .libs/pango-color.o .libs/pango-context.o .libs/pango-coverage.o .libs/pango-engine.o .libs/pango-fontmap.o .libs/pango-fontset.o .libs/pango-glyph-item.o .libs/pango-item.o .libs/pango-layout.o .libs/pango-markup.o .libs/pango-renderer.o .libs/pango-script.o .libs/pango-tabs.o .libs/pango-utils.o .libs/reorder-items.o .libs/shape.o .libs/pango-enum-types.o -all_load mini-fribidi/.libs/libmini-fribidi.a -L/usr/X11R6/lib -L/sw/lib /sw/lib/ libgobject-2.0.dylib /sw/lib/libgmodule-2.0.dylib /sw/lib/libglib-2.0.dylib /sw/lib/libintl.dylib /sw/lib/libiconv.dylib -lm -install_name /sw/lib/libpango-1.0.0.dylib -compatibility_version 1001 -current_version 1001.0 /usr/bin/libtool: internal link edit command failed ld: warning prebinding disabled because dependent library: /sw/lib/ libgobject-2.0.0.dylib is not prebound ld: warning multiple definitions of symbol _locale_charset /sw/lib/libiconv.dylib(localcharset.o) definition of _locale_charset /sw/lib/libintl.dylib(localcharset.o) definition of _locale_charset ld: Undefined symbols: _environ make[4]: *** [libpango-1.0.la] Error 1 make[4]: *** Waiting for unfinished jobs.... make[3]: *** [all-recursive] Error 1 make[2]: *** [all] Error 2 make[1]: *** [all-recursive] Error 1 make: *** [all] Error 2 Expected results: No linker error. Does this happen every time? Happens every time I try to force all symbols to be resolved (i.e., *not* using -undefined suppress). Other information: OS X doesn't have an environ symbol...I guess it follows the Single Unix Specification a little closer than other platforms, so when gutils.c says: /* According to the Single Unix Specification, environ is not in * any system header, although unistd.h often declares it. */ extern char **environ; That wish isn't sufficient to get it declared. In glib-2.6.6, that declaration was wrapped in #ifndef HAVE_UNSETENV, so there was no problem since OS X does have unsetenv(). The equivalent for OS X is NSGetEnviron(), so something like: #ifdef __APPLE__ #define environ (*_NSGetEnviron()) #else extern char **environ; #endif solves the problem for us. Not sure if there's a way to check for this specific functionality (instead of basing it on the platform). Have a ./configure check that tries various ways to access the env, crash if none work?
2005-08-17 Matthias Clasen <mclasen@redhat.com> * configure.in: Check for crt_externs.h and _NSGetEnviron. * glib/gutils.c: On Darwin, include crt-externs.h and define environ using _NSGetEnviron(). (#313731)
There's some hyphen/underscore confusion here...underscore is correct in the configure check; the #include is not.
2005-08-23 Matthias Clasen <mclasen@redhat.com> * glib/gutils.c: Fix the crt_externs.h include.
The ./configure check for NSGetEnviron() never propagates. There is a test for HAVE__NSGETENVIRON in glib/gutils.c but the AC_CHECK_FUNC(_NSGetEnviron) does not set it in config.h.
2005-10-19 Manish Singh <yosh@gimp.org> * configure.in: Use AC_CHECK_FUNCS for _NSGetEnviron, to get the config.h symbol automatically. Fixes bug #313731.