zoukankan      html  css  js  c++  java
  • linux下boost安装方法

    boost最新版本下载地址:
    http://sourceforge.net/project/showfiles.php?group_id=7586&package_id=8041

    下载boost_1_39_0.tar.gz    
    tar -zxvf boost_1_39_0.tar.gz 

    然后进入解压缩后的文件夹编译boost的编译器jam
    cd boost_1_39_0\tools\jam
    ./build_dist.sh 

    编译完后在这个目录下有编译出的bjam文件
    boost_1_39_0\tools\jam\stage\bin.Linuxx86

    把它copy到boost_1_39_0 然后在这个目录下运行命令编译:
    ./bjam "-sTOOLS=gcc" "--includedir=/usr/include" "--libdir=/usr/lib/boost" install

    开始编译,等待编译完成,需很长时间。
    关于bjam的后面的参数的设置:
    -sTOOLS=gcc 指定编译器为GCC
    --includedir=/usr/include/ 指定头文件的安装目录,我安装在/usr/include下。如果安装成功,将在/usr/include/生成目录boost_1_33,该目录下就是boost的头文件目录
    --libdir=/usr/lib/boost 指定boost的库文件的存放位置, 生成的 .a .so 文件将放在该目录下
    install 编译并安装boost


    测试:
    #include <iostream>
    #include 
    <boost/function.hpp>
    #include 
    <boost/bind.hpp>
        
        
    #define CALLBACK boost::function< void( const char* ) >
        
    void mysql_query( const char* sqlcmd, const CALLBACK *callback )
    {
         std::
    string result;
         result 
    = "result:";
         result 
    += sqlcmd;
         ( 
    *callback )( result.c_str() );
    }

    class Entity
    {
    public:
        
    void query()
         {
             CALLBACK func 
    = boost::bind( &Entity::queryDatabaseCallback, this, _1 );
             mysql_query( 
    "select * from test",  &func );
         }
        
        
    void queryDatabaseCallback( const char* result )
         {
             printf( 
    "%s\n", result );
         }    
    };


        
    void queryDatabaseCallback( const char* result )
    {
         printf( 
    "%s\n", result );
    }

    void query()
    {
         CALLBACK func 
    = &queryDatabaseCallback;
         mysql_query( 
    "select * from test1",  &func );
    }

    int main()
    {
         query();
         Entity e;
         e.query();
        
    return 0;
    }

    [liquidx@localhost ~]$ g++ -o test test.cpp
    [liquidx@localhost ~]$ ./test
    result:select * from test1
    result:select * from test
  • 相关阅读:
    使用 Fetch
    实现一个联系客服对话框的前端部分
    javascript之Object.defineProperty的奥妙
    vue之nextTick全面解析
    创建元素和删除元素
    vue.js应用开发笔记
    待字闺中之最多连续数的子集
    HDU-1212-Big Number
    虚方法【仅仅有虚方法或者抽象方法才干被子类方法重写】
    利用localStorage实现对ueditor编辑内容定时保存为草稿
  • 原文地址:https://www.cnblogs.com/rooney/p/2573284.html
Copyright © 2011-2022 走看看