我已经尝试了几周让Microsoft Visual Studio 2010为我创建一个带有SWIG的DLL.如果您已经完成了这个过程,那么您是否愿意提供一个深思熟虑的逐步流程解释?我在网上到处寻找并花了很多时间试图这样做; 但是我发现的所有教程都已过时或解释不清楚.
我成功地用cygwin完成了这个过程; 但正如你们中的一些人所知,cygwin DLL并不是很实用.
因此,我知道.i,.cpp和.h文件可以一起创建DLL.我只需要知道如何使用Visual Studio C++ 2010执行此操作.我所针对的语言是Python.
请不要将我介绍给其他网站; 因为很有可能我已经去过那里并试过了.此外,请不要嗤之以鼻的评论,因为我在不久的将来让它工作非常重要.
非常感谢您的帮助!
我在Python中使用Visual C++(由boost包装)的c ++代码时遇到了很多麻烦.
好吧,我正在使用的工具是:Visual Studio 2010,BoostPro 1_47,Windows 7和Python 2.7(32位).
我有以下代码在Visual Studio 2010中很好地编译:
#define BOOST_PYTHON_STATIC_LIB
#include <boost/python.hpp>
using namespace boost::python;
struct World
{
void set(std::string msg) { this->msg = msg; }
std::string greet() { return msg; }
std::string msg;
};
BOOST_PYTHON_MODULE(hello)
{
class_<World>("World")
.def("greet", &World::greet)
.def("set", &World::set);
}
Run Code Online (Sandbox Code Playgroud)
它的格式为:Win32控制台应用程序>>>空项目/ DLL.
在"项目属性"中:
VC++ DIRECTORIES:
I added:
>>> INCLUDE DIRECTORIES: C:\Program Files\boost\boost_1_47;C:\Python27\include .
>>> LIBRARY DIRECTORIES: C:\Program Files\boost\boost_1_47\lib;C:\Python27\libs
Run Code Online (Sandbox Code Playgroud)
所有这些都使c ++文件构建,但后来我无法从Python访问它.
当我尝试使用模块时,这就是Python所说的:
">>> import hello
Traceback (most recent call last):
File "<pyshell#0>", line 1, …Run Code Online (Sandbox Code Playgroud) 我正在学习如何在Windows上使用SWIG.
以下是我的c ++代码:
/* File : example.cxx */
#include "example.h"
#define M_PI 3.14159265358979323846
/* Move the shape to a new location */
void Shape::move(double dx, double dy) {
x += dx;
y += dy;
}
int Shape::nshapes = 0;
double Circle::area(void) {
return M_PI*radius*radius;
}
double Circle::perimeter(void) {
return 2*M_PI*radius;
}
double Square::area(void) {
return width*width;
}
double Square::perimeter(void) {
return 4*width;
}
Run Code Online (Sandbox Code Playgroud)
这是我的头文件:
/* File : example.h */
class Shape {
public:
Shape() {
nshapes++;
}
virtual ~Shape() { …Run Code Online (Sandbox Code Playgroud)