0

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;
}
martineau
  • 119,623
  • 25
  • 170
  • 301
PxG
  • 43
  • 6

1 Answers1

1

I think I found a solution for this.

Since I hadn't a .h file there was a declaration of the function but no definition. Either adding an header file or declare the function as an inline function helps, to get around this compiling error.

PxG
  • 43
  • 6