我正在尝试将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;
}
我想我找到了解决办法。你知道吗
因为我没有
.h
文件,所以有一个函数声明,但没有定义。添加头文件或将函数声明为inline
函数都有助于避免此编译错误。你知道吗相关问题 更多 >
编程相关推荐