[Python-Dev] How to force export of a particular symbol from python.exe?
Mark Dickinson
dickinsm at gmail.com
Sun Dec 14 21:49:31 CET 2008
Hi all,
I'm having some trouble making some bits of the Python core code
available to extension modules. Specifically, I'm trying to add a
function 'Py_force_to_memory' to Python/pymath.c and then use
it (via a macro) from Modules/cmathmodule.c. But importing of
the cmath module fails with a 'Symbol not found' error. The
function is declared with a 'PyAPI_FUNC' in Python/pymath.h.
Here's the relevant portion of the make output:
*** WARNING: renaming "cmath" since importing it failed:
dlopen(build/lib.macosx-10.3-i386-2.7/cmath.so, 2): Symbol not found:
_Py_force_to_memory
Referenced from:
/Users/dickinsm/python_source/branches/trunk/build/lib.macosx-10.3-i386-2.7/cmath.so
Expected in: dynamic lookup
This is a non-debug trunk build, on OS X (10.5.5), with all
the defaults. I'm using Apple's standard toolchain (gcc 4.0.1,
Darwin linker). The patch I'm building with can be seen at:
http://bugs.python.org/issue4575
(It's the first of the two patches there, called 'force_to_memory.patch'.)
I think I understand the cause of this problem; I just don't know how
to fix it. The cause seems to be that none of the symbols in pymath.o
is used in the Python executable; they're used only in the extension
modules. So while the '_Py_force_to_memory' symbol appears in
libpython2.7.a, it doesn't appear in the python.exe executable; hence
the above error.
If I move the definition of Py_force_to_memory from Python/pymath.c
to Objects/floatobject.c then everything works as expected.
Questions:
(1) Is this an OS X only problem?
(2) Is there an easy way to force a particular symbol (or all the
symbols from a particular object file) to be exported in the Python
executable, so that it's available to a dynamically loaded extension
module?
I've found the -u option to gcc, but this doesn't seem like a
particularly portable solution. Of course, if this problem exists
only on OS X, then the solution doesn't need to be portable.
Thanks,
Mark
More information about the Python-Dev
mailing list