SWIG help for newbie

Charles Medcoff cmedcoff at my-deja.com
Sun Sep 24 16:43:52 EDT 2000


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.

The generated shadow class looks ok, but of course I have not tried it
yet.

Header: HelloWorld

class HelloWorld
{
public:
 char* Message();
};

Implementation File : HelloWorld.cpp
#include "HelloWorld.h"
char* HelloWorld::Message(){ return "Hello World"; }

Interface file: HelloWorld.i

%module HelloWorld
%{
#include "HelloWorld.h"
%}

%include "HelloWorld.h"

Thanks,
Chuck


Charles E. Medcoff, MCP
Senior Systems Engineer
Pyramid Solutions
1850 Research Drive
Suite 300
Troy, MI 48083
248-524-3892 ext 262


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list