博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Linux 下boost python库的使用一
阅读量:7050 次
发布时间:2019-06-28

本文共 2138 字,大约阅读时间需要 7 分钟。

折腾折腾就会了

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

 我的环境: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 <iostream>

#include <string>

   

#define BOOST_DATE_TIME_NO_LIB

#include <boost/thread.hpp>

#include <boost/date_time/gregorian/gregorian.hpp>

#include <boost/date_time/posix_time/posix_time.hpp>

#include <boost/date_time/local_time/local_time.hpp>

   

#include <boost/python.hpp>

   

int main()

{

using namespace boost;

using namespace std;

using namespace boost::posix_time;

using namespace boost::gregorian;

using namespace boost::python;

          

cout<<"hello world"<<endl;

   

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

 

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

Py_Initialize();

   

if(Py_IsInitialized() == 1)

{

cout<<"Python Version:"<< Py_GetVersion() <<endl;

}

else

{

cout<<"Python error"<<endl;

return 0;

}

   

python::list l;

   

l.append("zelda");

l.append(2.236);

   

cout<<string(extract<string>(l[0]))<<endl;

cout<<extract<double>(l[1])<<endl;

   

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

   

cout<<string(extract<string>(t[1]))<<endl;

   

Py_Finalize();

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

   

       cout<<"time elapsed"<<posix_time::microsec_clock::local_time()-tm<<endl;

 

cin.get();

   

return 0;

}

   

编译

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

转载于:https://www.cnblogs.com/ningth/archive/2012/01/31/2333936.html

你可能感兴趣的文章
图形语言 Kgo
查看>>
兄弟连第10节课
查看>>
调整Virtual Box硬盘大小
查看>>
case 格式
查看>>
Windows下Apache服务器中自动配置二级子域名
查看>>
【Tomcat】日常遇到的Tomcat报错及解决方法
查看>>
Transform Map - Ignore Row if any fields are empty
查看>>
SVG绘制loading效果
查看>>
在kubernets中搭建jenkins服务
查看>>
iEclipse-不只是Eclipse的开发者社区
查看>>
Oracle个人的一些记录
查看>>
20.分屏查看命令 less命令
查看>>
感谢付费客户不覺流年似水(271558528) 对C#ASP.NET通用权限管理组件的改进意见,已修正...
查看>>
MySQL5.6.17学习笔记(四)复合分区及分区管理
查看>>
android 让 TextView 自带滚动条
查看>>
PHP过滤常见html标签的正则表达式
查看>>
注册与登录界面的美化
查看>>
win2003远程桌面不自动注销,自动锁定时间
查看>>
Shell脚本
查看>>
RPM包管理
查看>>