zoukankan      html  css  js  c++  java
  • Linux 下boost python库的使用一

    折腾折腾就会了

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

     我的环境:rhel 6.2 x86_64

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

    http://www.boost.org/doc/libs/1_48_0/more/getting_started/unix-variants.html

       

    使用以下参数编译,编译日志放到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)

  • 相关阅读:
    Python基础Day2
    HDU
    HDU
    BZOJ
    Gym
    UVA
    UVA
    UVA
    UVA
    BZOJ
  • 原文地址:https://www.cnblogs.com/ningth/p/2333936.html
Copyright © 2011-2022 走看看