[patch] bug #5412: Compile failing with 'Undefined symbols: "_environ"

Andrew Tanner andrew.tanner at isilon.com
Sun Jul 6 00:12:34 GMT 2008


Hi Samba team,

This patch fixes a bug I filed a while back (https://bugzilla.samba.org/show_bug.cgi?id=5412 
) that is causing the latest v4-0-test/stable heimdal (and perhaps  
other branches?) to fail to compile on OSX. Here is the explanation  
from the Mac OSX Man Page for environ(7) as to why environ can't be  
accessed directly.

PROGRAMMING
      Programs can query and modify the environment, using the  
environment rou-tines routines
      tines getenv(3), putenv(3), setenv(3) and unsetenv(3).  Direct  
access can
      be made through the global variable environ, though it is  
recommended
      that changes to the enviroment still be made through the  
environment rou-tines. routines.
      tines.

      Shared libraries and bundles don't have direct access to  
environ, which
      is only available to the loader ld(1) when a complete program is  
being
      linked.  The environment routines can still be used, but if  
direct access
      to environ is needed, the _NSGetEnviron() routine, defined in
      <crt_externs.h>, can be used to retrieve the address of environ  
at run-time. runtime.
      time.

diff --git a/source/heimdal/lib/roken/roken.h.in b/source/heimdal/lib/ 
roken/roken.h.in
index 82473d7..a3408f2 100644
--- a/source/heimdal/lib/roken/roken.h.in
+++ b/source/heimdal/lib/roken/roken.h.in
@@ -445,8 +445,13 @@ extern int opterr;
  #endif

  #if !HAVE_DECL_ENVIRON
+#ifdef __APPLE__
+#include <crt_externs.h>
+#define environ (*_NSGetEnviron())
+#else
  extern char **environ;
  #endif
+#endif

Thanks,
Andrew


More information about the samba-technical mailing list