每次编译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