boost.python 使用
来源:互联网 发布:视频文件加密软件 编辑:程序博客网 时间:2024/06/10 12:02
(1) python-dev 安装
sudo apt-get install python-dev
(2) boost.python 库的安装
sudo ./bjam toolset=gcc --build-type=complete --layout=versioned --with-python install
(3) boost_python_test.cpp
#include <boost/python.hpp>
#include <Python.h>
#include <string>
std::string hello_func()
{
return "GET BOOST!!!";
}
using namespace boost::python;
// export interface
BOOST_PYTHON_MODULE(emo)
{
// like python function defition
def("hello", hello_func, "greet");
}
编译成动态库
g++ -c -fPIC boost_python_test.cpp -I/usr/local/include/boost-1_53/ -I/usr/include/python2.7 -o boost_python_test.o
g++ -shared -Wl,-soname,emo.so -o emo.so boost_python_test.o -lpython2.7 -lboost_python-gcc46-1_53
注意: 如果没有-lpython2.7
Traceback (most recent call last):
File "export.py", line 3, in <module>
import emo
ImportError: /home/xuebingyuan/project/python/emo.so: undefined symbol: _ZNK5boost6python7objects21py_function_impl_base9max_arityEv
http://stackoverflow.com/questions/1780003/import-error-on-boost-python-hello-program
(4) import emo后
Traceback (most recent call last):
File "export.py", line 3, in <module>
import emo
ImportError: libboost_python-gcc46-1_53.so.1.53.0: cannot open shared object file: No such file or directory
cd /etc/ld.so.conf.d
vim boost.conf #这里写上boost库编译生成的库路径/usr/local/lib
ldconfig
http://bbs.python123.com/thread-589-1-1.html
(5) python
>>> import emo
>>> help(emo)
>>> emo.hello()
'GET BOOST!!!'
>>>
- Boost.Python使用小结
- 使用Boost.Python
- boost python的使用
- boost python 使用
- boost.python 使用
- 使用Boost.Python开发
- boost.python vector_indexing_suite 使用注意事项
- Boost.python 编译和使用
- python 使用Boost.python 调用c++
- 使用Boost.Python构建混合系统
- 使用Boost.Python构建混合系统
- boost.python 使用时注意小事项
- 使用boost::python的链接出错
- 使用boost.python进行混合开发
- 使用boost实现python调用c++
- Boost.Python:安装使用(兼具Boost.Python库中Python编译版本的修改)
- Boost.Python
- 使用 Boost.Python 嵌入 Python 模块到 C++
- iOS 第五天
- tab选项卡
- HTML 文字行间距与文字间距属性
- 深入探讨集群存储高可用方法
- hdu 超级楼梯
- boost.python 使用
- 大话设计模式之装饰模式
- C++ Primer 中文版 学习笔记(十四)
- python生成器
- Java事务处理总结
- 记录一些体会
- php filter函数
- 数据库
- android获取源代码、编译、命令