I'm currently trying to import a c++ dll into a python script. For now I want to import a very simple dll with just one function (for testing). As I worked my way through the detailed instruction from How to create a DLL with SWIG from Visual Studio 2010, there are two linking errors I don't really understand.
Everything worked until Step 25 (with an additional preprocessor definition for the generated _wrapper.cxx
to bypass strcpy
for now).
As soon as I try to build the project (everything compiles without a problem), I get this output from VS:
my_f.obj : error LNK2005: "int __cdecl cubes(int const &)" (?cubes@@YAHAEBH@Z) already defined in my_f.obj
Creating library C:\work\example64\my_f\x64\Release\_my_f.lib and object
C:\work\example64\my_f\x64\Release\_my_f.exp
C:\work\example64\my_f\x64\Release\_my_f.pyd : fatal error LNK1169: one or more multiply defined symbols found
Done building project "my_f.vcxproj" -- FAILED.
I'm working with a 64 Bit system and the installed python (3.6) is a x64 version (no debug though).
My .i
file looks like this:
%module cube
%{
#include "my_f.cpp"
%}
%include my_f.cpp
And the .cpp
file with the code is the following one:
#include "stdafx.h"
int cubes(const int &a)
{
return a * a*a;
}