extending python: c++ problem

Fredrik Lundh effbot at telia.com
Thu Mar 30 19:14:26 CEST 2000

Torsten H”rmann <torsten.hoermann at telekom.de> wrote:
> Does anyone know about the following problem and have a solution?
> I've written a python extension using c++. No Problems with msvc, but on
> HPUX with aCC. When importing the <iostream.h>, the python interpreter can
> not find the "initmod" function in the created lib. Error message:
> >>> import mod
> Traceback (innermost last):
>   File "<stdin>", line 1, in ?
> ImportError: dynamic module does not define init function (initmod)
> >>>

name mangling problems?

using "nm" to figure out what happens to you "initmod" function
might give you some clues...  (maybe iostream.h

the README and Misc/HPUX-Notes contain additional information
on building shared libraries under HPUX:


    HP-UX: Please read the file Misc/HPUX-NOTES for shared libraries.
    When using threading, you may have to add -D_REENTRANT to the
    OPT variable in the top-level Makefile; reported by Pat Knight
    this seems to make a difference (at least for HP-UX 10.20)
    even though config.h defines it.


    There are two important points.  First, the python executable must be
    linked with the -E option to explicitly export all symbols.  This
    works with the vanilla interpreter, but I am not sure how friendly it
    will be when I try to embed the interpreter in a larger application.
    It may be necessary to hand tune the exports using the -e option.
    Anyway, the additional flag to $(CC) is "-Wl,-E", which passes the -E
    flag to the compiler.  My link line (from an actual run) looks like

        cc config.o -Wl,-E libModules.a  ../Python/libPython.a
        ../Objects/libObjects.a ../Parser/libParser.a   -lm  -ldld
        -o python

    [Guido's note: as of Python 1.5, replace the four libraries with

    Second, the dynamic module must be compiled with the +z option to make
    it position independent and then linked into a shared library:

        ld -b -o <modName>module.sl <object list>

    The -b tells the linker to produce a shared library.

hope this helps!


More information about the Python-list mailing list