[转]vs2010用 boost.python 编译c++类库 供python调用
转自:http://blog.csdn.net/wyljz/article/details/6307952
VS2010建立一个空的DLL
项目属性中配置如下
链接器里的附加库目录加入,python/libs(python的安装目录中),boost/vs2010/lib(生成的boost的目录中)
c/c++的附加库目录加入,boost(boost的下载目录),python/include(python的安装目录)
代码文件加入引用
#include <boost/python.hpp>
生成的DLL文件,需改成和导出模块一致的名称,后缀为PYD
将此PYD文件与生成的BOOST/LIB中的boost_python-vc100-mt-1_46_1.dll 一同拷入工作目录,在此目录中新建py文件,就可以 直接 import 模块名,进行使用
示例:hello.cpp
- #include <iostream>
- using namespace std;
- class Hello
- {
- public:
- string hestr;
- private:
- string title;
- public:
- Hello(string str){this->title=str;}
- string get(){return this->title;}
- };
示例:hc.h 继承hello的子类
- #pragma once
- #include "hello.cpp"
- class hc:public Hello
- {
- public:
- hc(string str);
- ~hc(void);
- int add(int a,int b);
- };
hc.cpp
- #include "hc.h"
- hc::hc(string str):Hello(str)
- {
- }
- hc::~hc(void)
- {
- }
- int hc::add(int a,int b)
- {
- return a+b;
- }
导出的类pyhello.cpp
- #include "hc.h"
- #include <boost/python.hpp>
- BOOST_PYTHON_MODULE(hello_ext)
- {
- using namespace boost::python;
- class_<Hello>("Hello",init<std::string>())
- .def("get",&Hello::get)
- .def_readwrite("hestr",&Hello::hestr);
- class_<hc,bases<Hello>>("hc",init<std::string>())
- .def("add",&hc::add);
- }
python项目中调用 dll的目录包含文件:
1,boost_python-vc100-mt-1_46_1.dll
2,dll.py 调用dll的py文件
3,hello_ext.pyd 由上述c++生成的dll文件改名而成
dll.py内容:
- import hello_ext
- he=hello_ext.Hello("testdddd")
- print he.get()
- he.hestr="ggggddd"
- print he.hestr
- te=hello_ext.hc("fffff")
- print te.get()
- te.hestr="ddffg"
- print te.hestr
- print te.add(33,44)
[转]vs2010用 boost.python 编译c++类库 供python调用的更多相关文章
- Go 程序编译成 DLL 供 C# 调用。
Go 程序编译成 DLL 供 C# 调用. C# 结合 Golang 开发 1. 实现方式与语法形式 基本方式:将 Go 程序编译成 DLL 供 C# 调用. 1.1 Go代码 注意:代码中 ex ...
- Matlab函数编译成dll供c调用
一 编译dll 在Command Window窗口中输入mbuild -setup,然后会出现语句,是否安装编译器,选择n,因为机子上已经安装了C/C++/C#的编译器,选择VS2010.
- OWIN 自宿主模式WebApi项目,WebApi层作为单独类库供OWIN调用
OWIN是Open Web Server Interface for .NET的首字母缩写,他的定义如下: OWIN在.NET Web Servers与Web Application之间定义了一套标准 ...
- vs2010配备boost编程环境
vs2010配备boost编程环境 vs2010配置boost编程环境 第一步:下载boost,我下载的方法是从http://www.boost.org/上找最新的下载.名字叫boost_1_53_0 ...
- python 网络请求类库 requests 使用
python 网络请求类库 requests 使用 requests是 为python封装的强大 REST 操作类库 githubhttps://github.com/kennethreitz/req ...
- Boost库编译安装
一.Boost库介绍 Boost库是一个经过千锤百炼.可移植.提供源代码的C++库,作为标准库的后备,是C++标准化进程的发动机之一.Boost库由C++标准委员会库工作组成员发起,其 ...
- python安装第三方类库的方法
1.先到官网 http://pypi.python.org/pypi/setuptools 下载setuptools.exe文件并安装 点击 ez_setup.py进入, 并将内容复制下来, 保存为本 ...
- 2.准备Python编译环境
2.准备Python编译环境 2.1下载Python2.7.6.tgz.ipython1.2.1.tgz.sqlite-autoconf-3071401.tar.gz 2.2安装Python2.7.6 ...
- linux gcc 编译动态类库(.so)和静态类库(.a)
linux gcc 编译动态类库(.so)和静态类库(.a) 我的编译环境 ubuntu desktop 16.04 一:测试代码 测试有3个文件:AB.h,AB.c,test.c //AB.h vo ...
随机推荐
- 获取url "?" 后面的字符串
今天写了一个URL “?” 后面的字符串 来改变当前页面的状态 首先需要获取当前页面的URL console.log(widow.location) 之后页面就会打印出来当前的URL 之后我们获取UR ...
- C# 关键字this用法
1.this代表当前类的实例对象 public class Test { public string Name{get;set;} public void TestChange(string strN ...
- 一个神奇的???whatever~~
一个神奇的类,用来封装消息数据,统一数据传递接口,从unity引擎源码拷贝而来. #include <iostream> #include <assert.h> #includ ...
- Redis常用命令与高级应用
附: 127.0.0.1:6379> set xiaofei 小飞 OK 127.0.0.1:6379> get xiaofei "\xe5\xb0\x8f\xe9\xa3\x9 ...
- 数组的高级API-sort
按升降序排列数组项.本身存在的问题:只能通过第一位排列.解决方法:通过回调函数进行规制设置. a - b 升序. b - a 降续. 其内部运用了冒泡排序 <!DOCTYPE html> ...
- setTimeout中调用this
项目案例: 左右切换tab容器的动作,封装到一个对象中: var slidingComp = { startX : 0 , moveX : 0 , ...... start : function(e) ...
- 利用htmlparser读取html文档的内容
1.添加相关的的jar htmlparser-2.1.jar 2.方法和代码 public static String readHtml(File html) { String htmlPath = ...
- python day21 ——面向对像-反射 getattr,内置方法
一.反射:用字符串数据类型的变量名来访问这个变量的值 上代码^_^ # class Student: # ROLE = 'STUDENT' # @classmethod # def check_cou ...
- 剑指Offer 20. 包含min函数的栈 (栈)
题目描述 定义栈的数据结构,请在该类型中实现一个能够得到栈中所含最小元素的min函数(时间复杂度应为O(1)). 题目地址 https://www.nowcoder.com/practice/4c77 ...
- 实验楼 MySQL 基础课程 挑战:搭建一个简易的成绩管理系统的数据库
传送门:https://www.shiyanlou.com/courses/running 介绍 现需要构建一个简易的成绩管理系统的数据库,来记录几门课程的学生成绩.数据库中有三张表分别用于记录学生信 ...