一、安装
刚刚使用linux系统,对很多系统命令和操作方式还不是很熟悉。想装个boost库,在网上看了几篇教程根本没弄明白,终于,用三行命令解决了。
yum install boost
yum install boost-devel
yum install boost-doc
二、使用
对于我这样的小白来说,使用动态链接库时要添加链接我是不知道的,后来也是自己慢慢摸索出来了。
首先测试头文件。
#include
#include <boost/filesystem.hpp>
int main()
{
std::cout<<“hello,world”<<std::endl;
return 0;
}
使用 g++ test.cpp -o test 编译 ./test 执行
再测试需要用到二进制库的功能模块
#include
#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
恭喜你,成功了!
这篇博客适合Linux新手,介绍了如何通过yum命令轻松安装Boost库,并详细讲述了如何进行基本的使用,包括测试头文件和动态链接库的添加,帮助读者理解如何在C++程序中使用Boost文件系统模块。
1460

被折叠的 条评论
为什么被折叠?



