boost.python 使用
2013-07-26 16:55
176 查看
(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!!!'
>>>
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 使用
- 记录xgboost python 线性回归使用方法
- boost.python vector_indexing_suite 使用注意事项
- 使用 Boost.Python 嵌入 Python 模块到 C++
- boost python的使用
- Boost.Python:安装使用(兼具Boost.Python库中Python编译版本的修改)
- 让主程序可以通过python脚本扩展功能及boost.python的使用
- 使用boostpython小结
- 使用Boost.Python构建混合系统
- 使用boost.python在python调用C++接口(windows)
- boost::python的使用
- C++使用boost python开发后发布程序需要注意的几点
- Boost.python 编译和使用
- 使用boost.python静态库
- boost.python 使用时注意小事项
- 使用boost实现c++与python的相互调用
- xgboost+python参数介绍的简单使用
- 使用 Boost.Python 嵌入 Python 模块到 C++
- [转]在OS X 中安装boost.python, 使用homebrew
- C++使用boost python import 其他路径的模块