swig and init_module or initmodule, windows XP

Thomas Heller theller at python.net
Tue Jun 17 12:33:23 EDT 2003


"Thomas Jung" <jung-paz at t-online.de> writes:

> (BTW: what is top-posting ? How did I possibly do that ? I am sitting in
> front of a windows machine, using outlook, and not really familiar with
> windows. My family is forcing me now to use this  :-)

See http://jargon.watson-net.com/jargon.asp?w=top-post
and also http://jargon.watson-net.com/jargon.asp?w=bottom-post.

Searching the internet will also show a lot of links for this topic.

It boils down to this (taken from the second URL I cited):

  Hackers consider that the best practice is actually to excerpt only
  the relevent portions of the parent message, then intersperse the
  poster's response in such a way that each section of response appears
  directly after the excerpt it applies to. This reduces message bulk,
  keeps thread content in a logical order, and facilitates reading.

>> >> "Jung-Paz" <jung-paz at t-online.de> writes:
>> >>
>> >> > I am using Python2.2, mingw and Swig 1.3.19, Windows XP, and
>> >> > trying to build a module using the distutils.
>>
>> >> > Basically it works, but in the final linking step I get an
>> >> > undefined reference to "initexample" (the module name is
>> >> > example).
>>
>> >> > This sounds reasonable, as the file example_wrap.c, as produced
>> >> > by swig, contains only a function "init_example.c".  If I
>> >> > replace "init_example" by hand with "initexample" and compile
>> >> > and link by hand, everything is fine, and I get a loadable and
>> >> > usable module.  Any idea how I could make swig to produce other
>> >> > function names, or whatever could help ?
>> >>
>> >> Sounds like you should name your extension _example.pyd instead of
>> >> example.pyd...
>> >>
>> >
>> Can you post the setup script you use?
>>
>
> Here is setup.py:
> ========================================================================
> # setup.py
> import distutils
> from distutils.core import setup, Extension
>
> setup(name = "Simple example from swig website", version = "2.2",ext_modules
> = [Extension("example",["example.i","example.c"])])
> ========================================================================
>
> and example.c (from the SWIG tutorial):
[deleted]

I'm not using SWIG myself anymore, but a Python extension module named
"example" needs a function "initexample", and an extension module named
"_example" needs a function "init_example".

IMO you should change your setup script in this way:

========================================================================
# setup.py
import distutils
from distutils.core import setup, Extension
setup(name = "Simple example from swig website",
     version = "2.2",
     ext_modules = [Extension("_example",["example.i","example.c"])])
========================================================================

Does this work (when you do 'import _example' afterwards?

Thomas




More information about the Python-list mailing list