Jump to content
  • Advertisement
Sign in to follow this  
ove123

Help getting started with SWIG

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

If you intended to correct an error in the post then please contact us.

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 this post


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


Link to post
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 this post


Link to post
Share on other sites
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;



TrapezC.h:

#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 );
#endif


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!