# Help getting started with SWIG

This topic is 4104 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi i'm trying to use SWIG for the first time. I want to use some C functions from Python. I have a example.i file that looks like this: %module example %{ %} int testing(int a, int b); And my C code in example.c: int testing(int a, int b) { return a + b; } Now i used swig -python example.i This generated a example_wrap.c and a example.py. But what else do I need to get it to work? If I run the python file i get some error "No module named _example" So I guess I need to compile it somehow? I can only find unix examples of how to do it?: "unix % gcc -fpic -c example.c example_wrap.c -I/usr/local/include unix % gcc -shared example.o example_wrap.o -o example.so" But how do I fix this in Windows? I use Visual Studio 2005. Thanks

##### Share on other sites
You could get a windows port if the gcc compiler.
I use DJGPP but there's also MinGW. or you could figure out how to do this with the microsoft compiler.
I hope that helps. :)

##### Share on other sites
Thanks for the reply, I guess I'll try one of those. But if anyone knows how to do it with Visual studio 2005 I would be really thankfull.

##### Share on other sites
Here's a bat file I used to do some SWIG builds with Visual C++:

set PYLIB=E:\Python23\libsset PYINCLUDE=E:\Python23\Includeswig -python TrapezCpp.icl /LD /I %PYINCLUDE% TrapezCpp.c TrapezCpp_wrap.c /Fe_TrapezC.dll /link /LIBPATH:%PYLIB%

I'll include some of the other files for good measure. TrapezCpp.i:
/* Arild Fines *//* $Id$        */%module TrapezC%{#include "TrapezC.h"%}%include "TrapezC.h"%constant FUNC F1 = f_1;%constant FUNC F2 = f_2;

TrapezC.h:
#if !defined(TRAPEZC_H)#define TRAPEZC_Htypedef double(*FUNC)(double);double Trapez( double a, double b, FUNC func, int n );double f_1( double );double f_2( double );#endif