Jump to content
  • Advertisement
Sign in to follow this  
Prodigal Squirrel

Extending python with SWIG

This topic is 4496 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

I've been attempting to use SWIG with VC++ 6 in windows X to interface with python. I created a simple c++ source file and an interface file, and sucessfully ran swig on the interface file. I then created a simple DLL project in VC++ 6, included the source and wrapper files and set up neccessary directories and options. Now, I get 2 errors and a warning when I compile it. Here they are:
Linking...
pytonExt_wrap.obj : error LNK2005: "int __cdecl cppFunct(int)" (?cppFunct@@YAHH@Z) already defined in pythonExt.obj
pytonExt_wrap.obj : warning LNK4006: "int __cdecl cppFunct(int)" (?cppFunct@@YAHH@Z) already defined in pythonExt.obj; second definition ignored
   Creating library Debug/_pythonExt.lib and object Debug/_pythonExt.exp
Debug/_pythonExt.dll : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.

_pythonExt.dll - 2 error(s), 1 warning(s)
I do not understand at all why this is happening, any ideas?

Share this post


Link to post
Share on other sites
Advertisement
I've been using SWIG to provide a C# interface.

You say you added both the source and the wrapper files. You should compile your source into a lib and compile the wrapper seperately into a lib. The wrapper will eventually call your original code, but it's just a layer on top and must be compiled seperately.

hth,
CipherCraft

Share this post


Link to post
Share on other sites
Have you taken a look at Pyrex yet?
I'm sharing this in case you're doing some exploring to find alternative ways to create Python extensions. I've used SWIG too, and Pyrex seems a lot nicer to work with.

Share this post


Link to post
Share on other sites
I don't think this is directly caused by swig.

Did you write "cppFunct" in an header file?

Share this post


Link to post
Share on other sites
Well, that's your problem.

The function will be compiled twice.

Once in the compilation of pyext.cpp

and another time in the compilation of pyext_wrap.cxx (because the content of the pyext.cpp is included in it).

You should have an header file for the functions pyext.cpp and include it in your interface file instead.

Share this post


Link to post
Share on other sites
Quote:
Original post by Gorg
Well, that's your problem.

The function will be compiled twice.

Once in the compilation of pyext.cpp

and another time in the compilation of pyext_wrap.cxx (because the content of the pyext.cpp is included in it).

You should have an header file for the functions pyext.cpp and include it in your interface file instead.


So, do I just change the etension of my source file to a .h file? Then go about the process as normal? And is this how my interface file should be set up?

%module pythonExt
%{
#include "pythonext.hpp"
%}

extern int cppFunct(int x);

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!