• 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
  • 相关阅读:
    【转】 【技巧 】 数学难题大揭秘:减少计算错误的技术
    [转]Mathematical Induction --数学归纳法1
    Vector Calculus
    test latex1
    [转]架构蓝图--软件架构 "4+1" 视图模型
    What Is Mathematics?
    二项式展开
    游戏系统设计
    Golang游戏服务器与skynet的个人直观比较
    [转]透过 Linux 内核看无锁编程
  • 原文地址:https://www.cnblogs.com/rooney/p/2573284.html
Copyright © 2020-2023  润新知