473,382 Members | 1,648 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,382 software developers and data experts.

SWIG Python undefined reference

Hi,

I went through the SWIG tutorial for the example named "simple".

I managed to get to the first step, creating example_wrap.c using
swig, and doing:
"gcc -fpic -c example_wrap.c -IC:\python24\include " to create
example_wrap.o

But when I needed to compile the library file using:
"gcc -shared example_wrap.o -o examplemodule.so" I received a lot of
undefined reference compiler errors like:

example_wrap.o(.text+0x35a5):example_wrap.c: undefined reference to
`_imp__PyErr
_SetString'

there are many other similar errors all prefaced with _imp__Py, so I
am assuming there is a linker error with the python libraries. I have
adjusted my PATH variable to include all the python directories (libs/
dlls).

Does anyone here have any suggestions?

FILES FROM TUTORIAL:
//example.c
#include <time.h>
double My_variable = 3.0;

int fact(int n) {
if (n <= 1) return 1;
else return n*fact(n-1);
}

int my_mod(int x, int y) {
return (x%y);
}

char *get_time()
{
time_t ltime;
time(&ltime);
return ctime(&ltime);
}
//************************************************** *************

//example.i
%module example
%{
/* Put header files here or function declarations like below */
extern double My_variable;
extern int fact(int n);
extern int my_mod(int x, int y);
extern char *get_time();
%}

extern double My_variable;
extern int fact(int n);
extern int my_mod(int x, int y);
extern char *get_time();
//************************************************** *************

//setup.py
from distutils.core import setup, Extension

setup(name='example',
version = '1.0',
ext_modules=[
Extension('example', ['example.c', 'example.i'])
])
Jun 27 '08 #1
3 3654

Ok I found out how to do it using:

gcc -Ic:\python24\include -Lc:\python24\libs --shared example_wrap.c
example.c -lpython24 -o _example.pyd

but now I get a "dynamic module does not define init function" error
when I try to import it into python..

Anyone??

Soren
Jun 27 '08 #2
On Apr 29, 11:31 am, Soren <soren.skou.niel...@gmail.comwrote:
Ok I found out how to do it using:

gcc -Ic:\python24\include -Lc:\python24\libs --shared example_wrap.c
example.c -lpython24 -o _example.pyd

but now I get a "dynamic module does not define init function" error
when I try to import it into python..

Anyone??

Soren
In case anyone is having the same problem the solution for me was:

gcc example.c example_wrap.c -Ic:\python24\include -Lc:\python24\libs -
lpython24 -Xlinker -expoert-dynamic -shared -o _example.pyd

Soren
Jun 27 '08 #3
Instead of manually trying to get all the options to gcc correct you
might want to look at using distutils for compiling your extension.
See the SWIG documentation, section 30.2.2
(http://www.swig.org/Doc1.3/Python.html#Python_nn6)

Paul

Soren wrote:
Hi,

I went through the SWIG tutorial for the example named "simple".

I managed to get to the first step, creating example_wrap.c using
swig, and doing:
"gcc -fpic -c example_wrap.c -IC:\python24\include " to create
example_wrap.o

But when I needed to compile the library file using:
"gcc -shared example_wrap.o -o examplemodule.so" I received a lot of
undefined reference compiler errors like:

example_wrap.o(.text+0x35a5):example_wrap.c: undefined reference to
`_imp__PyErr
_SetString'

there are many other similar errors all prefaced with _imp__Py, so I
am assuming there is a linker error with the python libraries. I have
adjusted my PATH variable to include all the python directories (libs/
dlls).

Does anyone here have any suggestions?

FILES FROM TUTORIAL:
//example.c
#include <time.h>
double My_variable = 3.0;

int fact(int n) {
if (n <= 1) return 1;
else return n*fact(n-1);
}

int my_mod(int x, int y) {
return (x%y);
}

char *get_time()
{
time_t ltime;
time(&ltime);
return ctime(&ltime);
}
//************************************************** *************

//example.i
%module example
%{
/* Put header files here or function declarations like below */
extern double My_variable;
extern int fact(int n);
extern int my_mod(int x, int y);
extern char *get_time();
%}

extern double My_variable;
extern int fact(int n);
extern int my_mod(int x, int y);
extern char *get_time();
//************************************************** *************

//setup.py
from distutils.core import setup, Extension

setup(name='example',
version = '1.0',
ext_modules=[
Extension('example', ['example.c', 'example.i'])
])
Jun 27 '08 #4

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

Similar topics

1
by: Uwe Mayer | last post by:
Hi, I was trying to extend a Qt class in C++ and using this in my Python application. I got problems importing the python module: I was extending QListViewItem to QListViewItemNumeric. Then I...
2
by: superprad | last post by:
Hi I am trying to write a python wrapper for a C code I have using swig. when i try to compile the _wrap.c i get a bunch of these warnings and errors can anyone help Steps I followed : $swig...
0
by: Jerry He | last post by:
Hi, I just installed SWIG on Windows(Cygwin) and tried to use it to compile some of the example python programs. For the first two commands it produced no error swig -python example.i gcc -c...
0
by: Jerry He | last post by:
>From Jerry He: >For the third one however > ld -shared example.o example_wrap.o -o _example.so >It gave me a long list of errors listed at the end of >this email. Ok, I managed to get...
1
by: superprad | last post by:
Hi I am trying to write a python wrapper for a C code I have using swig. when i try to compile the wrap.c i get a bunch of these warnings and errors can anyone help $swig -python test_hk.c this...
2
by: ajikoe | last post by:
Hi, I tried to follow the example in swig homepage. I found error which I don't understand. I use bcc32, I already include directory where my python.h exist in bcc32.cfg. /* File : example.c...
0
by: Michael Yanowitz | last post by:
Hello: I am just trying out SWIG, but quickly ran into problems. Using Cygwin gcc, I tried the following: 1) Created example.c (as given on http://www.swig.org/tutorial.html ) /* File :...
0
by: newbie73 | last post by:
Going through the tutorial on http://swig.org, I created the example files (pasted below). After generating the _wrap file, I tried compiling (using mingw32) and received a lot of undefined...
2
by: mk | last post by:
Hello, I'm having terrible problems building C++ extension to Python 2.4 using SWIG. I'd appreciate if somebody knowledgeable at the subject took a look at it. swig-1.3.29, g++ (GCC) 4.1.1...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.