您的位置:首页 > 运维架构 > Linux

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

2016-02-02 10:49 519 查看
一、安装


刚刚使用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 执行

[b]再测试需要用到二进制库的功能模块[/b]

#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

恭喜你,成功了!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: