前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Linux下Boot的编译和使用

Linux下Boot的编译和使用

作者头像
卡尔曼和玻尔兹曼谁曼
发布2019-01-22 10:41:12
1.6K0
发布2019-01-22 10:41:12
举报
文章被收录于专栏:给永远比拿愉快

其实Linux下的编译安装过程和Window下的是差不多的(Windows下Boot的编译和使用) 首先在官网下载安装包进行解压,然后执行bootstrap.sh脚本。

代码语言:javascript
复制
tar -xzvf boost_1_62_0.tar.gz
cd boost_1_62_0
./bootstrap.sh

然后进行编译安装,默认安装路径是/usr/local。所以,相应的头文件在/usr/local/include/boost目录中,库文件在/usr/local/lib目录中。

代码语言:javascript
复制
sudo ./b2 install

最后,添加lib库自动搜索路径到/etc/ld.so.conf,然后ldconfig使设置生效。 具体操作为:运行命令sudo vim /etc/ld.so.conf,将”include /usr/local/lib”这句话添加进去,并保存退出vim编辑器。再运行ldconfig命令使之生效。

下面是书写代码进行编译。 还是上次的代码,编译命令如下:g++ file_utiles.cpp --std=c++11 -I/usr/local/include -L/usr/local/lib -lboost_system -lboost_filesystem -o file_utiles

代码语言:javascript
复制
#include <iostream>
#include <string>
#include "boost/filesystem.hpp"

using namespace boost;
using std::cout;
using std::string;


int main()
{
    string fileName("./readme.txt");
    auto filePath = filesystem::path(fileName);

    if (filesystem::exists(filePath))    // does path p actually exist?
    {   
        if (filesystem::is_regular_file(filePath))        // is path p a regular file?
            cout << filePath << " size is " << filesystem::file_size(filePath) << '\n';

        else if (filesystem::is_directory(filePath))      // is path p a directory?
            cout << filePath << " is a directory\n";

        else
            cout << filePath << " exists, but is not a regular file or directory\n";
    }   
    else
        cout << filePath << " does not exist\n";

    return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2016年10月08日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档