The way that dylib works on OS X prevents you from directly referencing things defined in the executable from an external library (there are kludge linker flags, but I don't recommend their usage).
The way to do it is to use crt_externs.h. I didn't come up with this by the way, it's all over OS X (and NeXT, the header is from 1995) compatible software, such as Python and TCL (just google for _NSGetEnviron). You can even setup macros to make it feel like you have "unix-like" access to your environment, for example:
extern char **environ;
Egregious spaces are because PyDS thinks that the C preprocessor directives are actually PyDS macros (or something to that syntax-error-causing-effect). Perhaps someone will tell me how to turn that off, or at least escape the code properly (hint, hint). Fortunately, I'm pretty sure that gcc doesn't care either way.
It seems that a few projects have tried to do this the wrong way, such as 4Suite. They use one of the kludge linker flags and an extern pointer to environ, but that doesn't actually work because they missed a different kludge linker flag ;) It may have worked under some conditions, such as with Apple's Python 2.2.0, but nobody should've been using that anyway.
|