boost python异常处理_Linux 下boost python库的使用一

折腾折腾就会了

-----------------------------------------------------

我的环境:rhel 6.2 x86_64

编译boost库,boost.org网站介绍的非常详细

使用以下参数编译,编译日志放到build.log中

sudo ./b2 stage --layout=tagged --build-type=complete --toolset=gcc architecture=x86 address-model=64>build.log 2>&1

问题与处理方法

1、bzip2的一些错误,解决方法

rpm -ivh bzip2-1.0.5-7.el6_0.x86_64.rpm

rpm -ivh bzip2-devel-1.0.5-7.el6_0.x86_64.rpm

2、boost库编译错误

rpm -ivh python-devel-2.6.6-29.el6.x86_64.rpm

3、xxx is not in the sudoers file

添加文件的写权限 chmod u+w /etc/sudoers

编辑/etc/sudoers文件。找到这一 行:"root ALL=(ALL) ALL"在起下面添加"xxx ALL=(ALL) ALL"(这里的xxx是你的用户名),然后保存

撤销文件的写权限。也就是输入命令"chmod u-w /etc/sudoers"

4、warning: dereferencing pointer does break strict-aliasing rules

Gcc 4.4版本编译器优化警告,没有关注

6、cant find zlib.h

rpm -ivh zlib-devel-1.2.3-27.el6.x86_64.rpm

应用

写个程序,代码如下

---------------------------------------------------

#include

#include

#define BOOST_DATE_TIME_NO_LIB

#include

#include

#include

#include

#include

int main()

{

using namespace boost;

using namespace std;

using namespace boost::posix_time;

using namespace boost::gregorian;

using namespace boost::python;

cout<

posix_time::ptime tm = posix_time::microsec_clock::local_time();

/*--------------------------------------------------------------python*/

Py_Initialize();

if(Py_IsInitialized() == 1)

{

cout<

}

else

{

cout<

return 0;

}

python::list l;

l.append("zelda");

l.append(2.236);

cout<(l[0]))<

cout<(l[1])<

python::tuple t = python::make_tuple("metroid","samus","ridley");

cout<(t[1]))<

Py_Finalize();

/*--------------------------------------------------------------python*/

cout<

cin.get();

return 0;

}

编译

编译时需要加上-lboost_python -lpython2.6 以及相应路径 (我的系统中为python2.6)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值