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(<ime);
return ctime(<ime);
}
//************************************************** *************
//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'])
]) 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
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
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(<ime);
return ctime(<ime);
}
//************************************************** *************
//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'])
])
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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 :...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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
|
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...
|
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...
| |