Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #91557
| From | "garyr" <garyr@fidalgo.net> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Building an extension module with SWIG |
| Date | 2015-05-30 18:54 -0700 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <mkdpne$k16$1@speranza.aioe.org> (permalink) |
| References | <mkco9p$gf8$1@speranza.aioe.org> |
"garyr" <garyr@fidalgo.net> wrote in message
news:mkco9p$gf8$1@speranza.aioe.org...
> I'm trying to create an extension module using SWIG. I've
> succeeded in generating a pyd file but when I import the module I get the
> error message: "SystemError: dynamic module not initialized properly." I
> added an initfoo() function but that didn't solve the problem. Below are
> the
> various files, a slightly modified version of a SWIG exmaple.
> I'm using Python 2.7
>
> What am I missing?
>
> //foo.c:
> #include "foo.h"
> double Foo;
> void initfoo()
> {
> Foo = 3.0;
> }
> int gcd(int x, int y) {
> int g;
> g = y;
> while (x > 0) {
> g = x;
> x = y % x;
> y = g;
> }
> return g;
> }
>
> #foo.h:
> extern void initfoo();
> extern double Foo;
> extern int gcd(int x, int y);
>
> #foo.i:
> %module example
> %inline %{
> extern int gcd(int x, int y);
> extern double Foo;
> %}
>
> #setup.py
> from setuptools import setup, Extension
> setup(name='foo',
> version='0.1',
> ext_modules=[Extension('foo', ['foo.c', 'foo.i'],
> include_dirs=['.'],
> depends=['foo.h', 'foo.i'],
> swig_opts=['-modern', '-I../include'],
> )],
> )
>
It's working! The first character of the name of the extension must be an
underscore; e.g.,
> ext_modules=[Extension('_foo', ['foo.c', 'foo.i'],
and the initfoo() function is not needed.
Thanks to all that replied to my post.
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Building an extension module with SWIG "garyr" <garyr@fidalgo.net> - 2015-05-30 09:22 -0700
Re: Building an extension module with SWIG Stefan Behnel <stefan_ml@behnel.de> - 2015-05-30 21:05 +0200
Re: Building an extension module with SWIG "garyr" <garyr@fidalgo.net> - 2015-05-30 13:48 -0700
Re: Building an extension module with SWIG "garyr" <garyr@fidalgo.net> - 2015-05-30 15:55 -0700
Re: Building an extension module with SWIG Stefan Behnel <stefan_ml@behnel.de> - 2015-05-31 07:28 +0200
Re: Building an extension module with SWIG "garyr" <garyr@fidalgo.net> - 2015-05-30 18:54 -0700
csiph-web