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

恭喜你,成功了!

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM