473,287 Members | 1,689 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

SWIG problems - "ImportError: dynamic module does not define......."

I have seen messages posted about this before, and there is a clear
reference to it in the manual, but I have been unable to find a
solution.

I'm on Slackware 9.1, kernel 2.6.0-test11, using Python 2.3.1 and
GCC 3.2.3 (both installed by default with Slackware) and SWIG 1.3.19,
compiled from source code.
I messed around a little on my own and couldn't get things to work
right,
so I copied the examples from the book, nearly verbatim but with some
minor changes to fit my configuration.

I copied the example code exactly into example.i and example.c, and
did
the following commands:
swig -python example.i
gcc -c example.c example_wrap.c -I/usr/include/python2.3
ld -shared example.o example_wrap.o -o _example.so
.... and several other times in the last command I tried some other
things like examplemodule.so and example.so. All of these worked
without
error, so I tried it from within Python, and got the usual error about
"ImportError: dynamic module does not define init function" when I
tried
'import example'. It made no difference if I added the path with all
the
files to sys.path; the same error occurred.

I tried this several times over, and I could never get it to work
right. The last helpful suggestion I saw on here was that I did not
make the init<whatever> function public by putting
/EXPORT:init<whatever> on the linker line, but that doesn't seem to be
what GNU ld understands

Any suggestions?

Thanks,
-Chris
Jul 18 '05 #1
2 6707
Hello,
I am not at my home office at the moment but you will probably find the
following link helpful:

http://groups.google.de/groups?hl=de...=UTF-8&oe=utf-
8&threadm=mailman.999029862.20314.python-
list%40python.org&rnum=7&prev=/groups%3Fhl%3Dde%26ie%3DUTF-8%26oe%3Dutf-
8%26q%3Dpython%2Bdistutils%2Bexport%26sa%3DN%26tab %3Dwg

The content is:
Section 5.2 of the Extending and Embedding the Python Interpreter says:
"The problem is that some entry points are defined by the Python runtime
solely for extension modules to use. If the embedding application does not
use any of these entry points, some linkers will not include those entries
in the symbol table of the finished executable. Some additional options are
needed to inform the linker not to remove these symbols.
Determining the right options to use for any given platform can be quite
difficult, but fortunately the Python configuration already has those
values.
To retrieve them from an installed Python interpreter, start an interactive
interpreter and have a short session like this:
import distutils.sysconfig
distutils.sysconfig.get_config_var('LINKFORSHARED' )
'-Xlinker -export-dynamic'
The contents of the string presented will be the options that should be
used.
If the string is empty, there's no need to add any additional options. The
LINKFORSHARED definition corresponds to the variable of the same name in
Python's top-level Makefile."
The '-Xlinker' tells gcc to pass '-export-dynamic' to ld. gcc itself seems
to ignore it otherwise.

Richard Sharp

c.******@softhome.net (Chris Hodapp) wrote in
<6e**************************@posting.google.com >:
I have seen messages posted about this before, and there is a clear
reference to it in the manual, but I have been unable to find a
solution.

I'm on Slackware 9.1, kernel 2.6.0-test11, using Python 2.3.1 and
GCC 3.2.3 (both installed by default with Slackware) and SWIG 1.3.19,
compiled from source code.
I messed around a little on my own and couldn't get things to work
right,
so I copied the examples from the book, nearly verbatim but with some
minor changes to fit my configuration.

I copied the example code exactly into example.i and example.c, and
did
the following commands:
swig -python example.i
gcc -c example.c example_wrap.c -I/usr/include/python2.3
ld -shared example.o example_wrap.o -o _example.so
... and several other times in the last command I tried some other
things like examplemodule.so and example.so. All of these worked
without
error, so I tried it from within Python, and got the usual error about
"ImportError: dynamic module does not define init function" when I
tried
'import example'. It made no difference if I added the path with all
the
files to sys.path; the same error occurred.

I tried this several times over, and I could never get it to work
right. The last helpful suggestion I saw on here was that I did not
make the init<whatever> function public by putting
/EXPORT:init<whatever> on the linker line, but that doesn't seem to be
what GNU ld understands

Any suggestions?

Thanks,
-Chris


Jul 18 '05 #2
rb*****@gmx.de (Richard Sharp) wrote in message news:<br************@ID-185495.news.uni-berlin.de>...
Hello,
I am not at my home office at the moment but you will probably find the
following link helpful:

http://groups.google.de/groups?hl=de...=UTF-8&oe=utf-
8&threadm=mailman.999029862.20314.python-
list%40python.org&rnum=7&prev=/groups%3Fhl%3Dde%26ie%3DUTF-8%26oe%3Dutf-
8%26q%3Dpython%2Bdistutils%2Bexport%26sa%3DN%26tab %3Dwg
<snip>
Richard Sharp


Thank you. That information, along with GCC's manual pages, helped me
to get everything working. What eventually worked was 'gcc example.c
example_wrap.c -I/usr/include/python-2.3 -Xlinker -export-dynamic
-shared -o _example.c'.

-Chris
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: David Eger | last post by:
I'm trying to make a very simple extension which will return a new copy of a C++ string object to python, and I'm segfaulting in the process. I'm using Python 2.2.2, SWIG 1.3.17 and g++ 3.3. Am I...
2
by: x-herbert | last post by:
Hi, I have a small test to "compile" al litle script as a WMI-Tester. The script include a wmi-wrapper and "insert" the Win32-modeles. here the code: my "WMI-Tester.py" ----- import wmi
2
by: Sebastian Stelzer | last post by:
Hi, I'am a beginner in Python and I have got a problem with the TKInter module. When I want to start e.g. pysol, I get following output: Traceback (most recent call last): File...
0
by: Bill Davy | last post by:
Hello, I am using SWIG-1.3.24 to make an extension (called SHIP) to Python2.4.1 and then running under IDLE (if that makes any difference) but when I "import SHIP" I get: >>> import SHIP ...
0
by: Bill Davy | last post by:
I am working with MSVC6 on Windows XP. I have created an MSVC project called SHIP I have a file SHIP.i with "%module SHIP" as the first line (file is below). I run SHIP.i through SWIG 1.3.24...
5
by: Bob | last post by:
Are they different names for the same concept ?
2
by: John Pye | last post by:
Hi all I understand that I can't hope to pass a FILE* from the Windows version of Python into a SWIG module that I've built using MinGW gcc/g+ +, because apparently the FILE* structure are...
1
by: Prof Rodney Coates | last post by:
Although I have been using Macs for a quarter of a century and was doing scientific programming in the '60's I am VERY new to Python on the Mac. I have been writing some very simple applications and...
4
by: Daniel | last post by:
Hello, I'm trying to build a very simple IPC system. What I have done is create Data Transfer Objects (DTO) for each item I'd like to send across the wire. I am serializing these using...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.