[Python-Dev] How to force export of a particular symbol from python.exe?

"Martin v. Löwis" martin at v.loewis.de
Sun Dec 14 22:06:19 CET 2008

> (1) Is this an OS X only problem?

Probably not. If nothing of pymath.c is actually needed when linking
the python executable, pymath.o will be excluded by the linker.

> (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?

That's not the issue. Had pymath.o been linked into python, it's
symbols would have been exported (is that proper use of English

To fix this, I see three solutions

1. Explicitly link the module to extensions which are known to
   require it, e.g. by explicitly adding it to the sources in
   setup.py. That might cause duplications, but would IMO be
   the cleanest solution (python.exe has no business in exporting
   standard math functions, IMO)

2. Explicitly link pymath.o to python.exe, instead of integrating
   it into libpythonxy.a. If the symbols need to be exposed through
   python.exe (for whatever reason), this is the clean way to do it.

3. Implicitly force linkage, by adding a dummy symbol to pymath.o
   which gets referenced from an object known to be linked into
   the interpreter. This has the least impact on the build process,
   but is the most hackish approach (IMO).


More information about the Python-Dev mailing list