linux(centos)下安装boost库及使用

一、安装

       刚刚使用linux系统,对很多系统命令和操作方式还不是很熟悉。想装个boost库,在网上看了几篇教程根本没弄明白,终于,用三行命令解决了。再见

      yum install boost

      yum install boost-devel

      yum install boost-doc

二、使用

    对于我这样的小白来说,使用动态链接库时要添加链接我是不知道的,后来也是自己慢慢摸索出来了。

   首先测试头文件。

 

[cpp] view plain copy
 
  1. #include <iostream>  
  2. #include <boost/filesystem.hpp>  
  3. int main()  
  4. {  
  5.     std::cout<<"hello,world"<<std::endl;  
  6.     return 0;  
  7. }  

   使用g++ test.cpp -o test  编译 ./test   执行
   再测试需要用到二进制库的功能模块

 

 

[cpp] view plain copy
 
  1. #include <iostream>  
  2. #include <boost/filesystem.hpp>  
  3.   
  4. using namespace boost::filesystem;  
  5.   
  6. int main(int argc, char *argv[])  
  7. {  
  8.   if (argc < 2) {  
  9.     std::cout << "Usage: tut1 path\n";  
  10.     return 1;  
  11.   }  
  12.   std::cout << argv[1] << " " << file_size(argv[1]) << std::endl;  
  13.   return 0;  
  14. }  

注意:这时我使用的是g++ test.cpp -o test -lboost_system -lboost_filesystem

 

执行 ./test, 输出

Usage: tut1 path

恭喜你,成功了!

 

posted on 2018-04-20 00:31  &大飞  阅读(3194)  评论(0编辑  收藏  举报

导航