After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 313731 - Undefined _environ symbol
Undefined _environ symbol
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
2.8.x
Other All
: Normal major
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks: 124277
 
 
Reported: 2005-08-17 15:17 UTC by Daniel Macks
Modified: 2005-10-19 18:37 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Daniel Macks 2005-08-17 15:17:39 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?
Comment 1 Matthias Clasen 2005-08-17 18:31:12 UTC
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)
Comment 2 Daniel Macks 2005-08-23 20:26:30 UTC
There's some hyphen/underscore confusion here...underscore is correct in the
configure check; the #include is not.
Comment 3 Matthias Clasen 2005-08-24 03:18:10 UTC
2005-08-23  Matthias Clasen  <mclasen@redhat.com>

        * glib/gutils.c: Fix the crt_externs.h include.

Comment 4 Daniel Macks 2005-10-19 17:53:53 UTC
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.
Comment 5 Manish Singh 2005-10-19 18:37:58 UTC
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.