Compile C ++ to python using swig

I am trying to compile a very simple file in python on windows and I am having a bad time.

The .i file is testfile.i:

%module testfile

%include "stl.i"

%{  
    int get_num() {
        return 3;
    }
%}  

int get_num() {
        return 3;
}

      

Swig function: {swig path} \ swig.exe -C ++ -python testfile.i

This works great, now I got a testfile.py file and a testfile_wrap.cxx file. Now I figured out that I need to compile this into a library (.pyd on windows). I tried:

{gcc path} \ gcc.exe -fPIC -shared testfile_wrap.cxx -o testfile_wrap.pyd -L. -LC: \ Python27 \ libs \ -lpython27 -IC: \ python27 \ include.

Here is the problem, I am getting many errors like these:

C:\Users\itay\AppData\Local\Temp\ccANsNeU.o:testfile_wrap.cxx:(.text+0xc00): undefined reference to `__imp_PyExc_MemoryError'
C:\Users\itay\AppData\Local\Temp\ccANsNeU.o:testfile_wrap.cxx:(.text+0xc13): undefined reference to `__imp_PyExc_IOError'
C:\Users\itay\AppData\Local\Temp\ccANsNeU.o:testfile_wrap.cxx:(.text+0xc26): undefined reference to `__imp_PyExc_RuntimeError'
C:\Users\itay\AppData\Local\Temp\ccANsNeU.o:testfile_wrap.cxx:(.text+0xc39): undefined reference to `__imp_PyExc_IndexError'

      

And it goes on and on.

What am I doing wrong?

thanks for the help

Update: I was able to call swig and compile / link using visual studio 2013, but I am getting the same error. I followed tutorials and it still doesn't work.

+3


source to share


1 answer


Solution: my python was 64 bit and it didn't work. Changed to 32 bit python and now it works (python 2.7.10)



+1


source







All Articles