Sign in to follow this  

Help getting started with SWIG

Recommended Posts

ove123    122
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 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" But how do I fix this in Windows? I use Visual Studio 2005. Thanks

Share this post

Link to post
Share on other sites
ove123    122
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 this post

Link to post
Share on other sites
Arild Fines    968
Here's a bat file I used to do some SWIG builds with Visual C++:

set PYLIB=E:\Python23\libs
set PYINCLUDE=E:\Python23\Include
swig -python TrapezCpp.i
cl /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;


#if !defined(TRAPEZC_H)
#define TRAPEZC_H

typedef double(*FUNC)(double);

double Trapez( double a, double b, FUNC func, int n );

double f_1( double );
double f_2( double );

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this