小编use*_*530的帖子

如何使用Visual Studio 2010中的SWIG创建DLL

我已经尝试了几周让Microsoft Visual Studio 2010为我创建一个带有SWIG的DLL.如果您已经完成了这个过程,那么您是否愿意提供一个深思熟虑的逐步流程解释?我在网上到处寻找并花了很多时间试图这样做; 但是我发现的所有教程都已过时或解释不清楚.

我成功地用cygwin完成了这个过程; 但正如你们中的一些人所知,cygwin DLL并不是很实用.

因此,我知道.i,.cpp和.h文件可以一起创建DLL.我只需要知道如何使用Visual Studio C++ 2010执行此操作.我所针对的语言是Python.

请不要将我介绍给其他网站; 因为很有可能我已经去过那里并试过了.此外,请不要嗤之以鼻的评论,因为我在不久的将来让它工作非常重要.

非常感谢您的帮助!

c++ python swig visual-studio-2010

20
推荐指数
1
解决办法
1万
查看次数

Boost Python Hello World示例不适用于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)

c++ python boost boost-python

7
推荐指数
1
解决办法
5544
查看次数

使用SWIG从包装的cpp文件创建DLL

我正在学习如何在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)

python dll swig

6
推荐指数
4
解决办法
1万
查看次数

标签 统计

python ×3

c++ ×2

swig ×2

boost ×1

boost-python ×1

dll ×1

visual-studio-2010 ×1