一、安装
刚刚使用linux系统,对很多系统命令和操作方式还不是很熟悉。想装个boost库,在网上看了几篇教程根本没弄明白,终于,用三行命令解决了。
yum install boost
yum install boost-devel
yum install boost-doc
二、使用
对于我这样的小白来说,使用动态链接库时要添加链接我是不知道的,后来也是自己慢慢摸索出来了。
首先测试头文件。
- #include <iostream>
- #include <boost/filesystem.hpp>
- int main()
- {
- std::cout<<"hello,world"<<std::endl;
- return 0;
- }
使用g++ test.cpp -o test 编译 ./test 执行
再测试需要用到二进制库的功能模块
- #include <iostream>
- #include <boost/filesystem.hpp>
- using namespace boost::filesystem;
- int main(int argc, char *argv[])
- {
- if (argc < 2) {
- std::cout << "Usage: tut1 path\n";
- return 1;
- }
- std::cout << argv[1] << " " << file_size(argv[1]) << std::endl;
- return 0;
- }
注意:这时我使用的是g++ test.cpp -o test -lboost_system -lboost_filesystem
执行 ./test, 输出
Usage: tut1 path
恭喜你,成功了!