【发布时间】:2020-02-07 13:14:31
【问题描述】:
我目前正在尝试将 c++ dll 导入 python 脚本。现在我想导入一个非常简单的 dll,只有一个函数(用于测试)。当我按照How to create a DLL with SWIG from Visual Studio 2010 的详细说明进行操作时,有两个我不太明白的链接错误。
在第 25 步之前一切正常(现在为 generated _wrapper.cxx 附加预处理器定义以绕过 strcpy)。
一旦我尝试构建项目(一切编译都没有问题),我会从 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.
我正在使用 64 位系统,安装的 python (3.6) 是 x64 版本(虽然没有调试)。
我的.i 文件如下所示:
%module cube
%{
#include "my_f.cpp"
%}
%include my_f.cpp
而带有代码的.cpp文件如下:
#include "stdafx.h"
int cubes(const int &a)
{
return a * a*a;
}
【问题讨论】:
标签: python c++ dll wrapper swig