c++ swig python

Bengt Richter bokr at oz.net
Tue Jan 14 15:28:26 EST 2003


On Mon, 13 Jan 2003 15:32:31 +0100, Oleg Seifert <misterxx at uni-koblenz.de> wrote:

>Hallo,
>
>ich habe eine einfache Klasse in c++ geschrieben.
>Dann habe ich mit Hilfe von SWIG aus dieser Klasse einen Python-Modul 
>(dll-Bibliothek) erstellt. [testfiles.dll + testfiles.lib]
>
>Ich habe diese Bibliothek mir einer kleiner c++-Anwendung testen können.
>Aber wenn ich diesen Modul in Python importiere ("import testfiles") 
>kriege ich die Fehlermeldung:
>
> >>> import testfiles
>Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>ImportError: dynamic module does not define init function (inittestfiles)
> >>>
>
>Woran könnte es liegen ? Was mache ich falsch ?
>
>Danke im Voraus.

I think the message probably means what it says ;-) I.e. either your
module dosn't define the initfunction, or the linker was not told to
export the name (e.g., a switch something like -link export:inittestfiles
or the equivalent directive in the source).

You will find info about init function here:

    http://www.python.org/doc/current/ext/methodTable.html

and a more general index here:

    http://www.python.org/doc/current/ext/ext.html


If you are running windows/msvc++6, you might find a command file (with adjustments
for your disk layout) like below useful (remove the '@REM ' if you don't run with
that already in your console window environment)

====< mkpydll.cmd >==============
@REM @d:\vc98\bin\vcvars32.bat
@cl -LD -nologo -Id:\python22\include %1.c -link -LIBPATH:D:\python22\libs -export:init%1
=================================

Then

    mkpydll testfiles

would recompile and link the single file testfiles.c, exporting inittestfiles

HTH,

Regards,
Bengt Richter




More information about the Python-list mailing list