SWIG help for newbie
howard at eegsoftware.com
howard at eegsoftware.com
Mon Sep 25 02:11:57 EDT 2000
On Sun, 24 Sep 2000 20:43:52 GMT, Charles Medcoff
<cmedcoff at my-deja.com> wrote:
>I've posted this to the SWIG newslist but didn't get any response. I'm
>hoping some here might help.
>
>Just getting started with writing Python extensions using SWIG (I'm new
>to extensions altogether). I've written a simple "Hello World"
>extension that just exposes function written in C. That was no
>problem.
>
>Now I'm attempting to expose a simple class written in C++. (A
>simple sample would be nice if anyone has a reference.)The following
>documents my attempt. (I'm using Visual C++ 6.0).
>
>%SWIG_EXE% -python -shadow -c++ -o $(ProjDir)\$(InputName)_wrap.cpp
>$(InputPath) where the input name is HelloWorld.i.
>
>The generated file initialize does not compile. I have to move the
>#include "Python.h" outside of the extern "C" statement. After this
>change it compiles fine. When I attempt to link I get complaints about
>an unresolved external initHelloWorld. The generated code does include
>a definition for initHelloWorldc. I cannot find a reference for
>initHelloWorld in the generated source code.
Robin Dunn kindly replied to my similar question with this Working
answer (which is already fixed in the 1.3x versions of SWIG):
In your pycdc3_wrap.cxx file you need to move the
#include <Python.h>
to be in front of
#ifdef __cplusplus
extern "C" {
#endif
You can make this change more permanent by editing pyexp.swg in SWIG's
library directory.
Howard Lightstone
EEGSoftware
howard at eegsoftware.com
More information about the Python-list
mailing list