树莓派安装boost库

使用环境

树莓派: raspberry 3B+

系统版本: NOOBS Version:3.4.0 Release date:2020-05-27

网上相关资料

https://raspberry-projects.com/pi/programming-in-c/boost-c-libraries/installing-and-using-boost

https://www.cnblogs.com/ch122633/p/8690235.html

方案

1、交叉编译安装(需要构建其环境,编译可能是将时间放在大量的试错、解决编译过程中的错误)。

2、找编译好的库安装。

过程

采用第二个方案,找编译好的库安装。

网上的方法:
raspberry-projects.com
sudo apt-get install libboost1.50-all
中文资源
sudo apt-get install libboost-dev
 

... 不好使

boost库有哪些呢,apt-cache搜搜有哪些资源

sudo apt-get update
sudo apt-cache search libboost

打印信息如下:

libboost-all-dev - Boost C++ Libraries development files (ALL) (default version)
libboost-atomic-dev - atomic data types, operations, and memory ordering constraints (default version)
libboost-atomic1.58-dev - atomic data types, operations, and memory ordering constraints
libboost-atomic1.58.0 - atomic data types, operations, and memory ordering constraints
libboost-atomic1.62-dev - atomic data types, operations, and memory ordering constraints
libboost-atomic1.62.0 - atomic data types, operations, and memory ordering constraints
libboost-atomic1.67-dev - atomic data types, operations, and memory ordering constraints
libboost-atomic1.67.0 - atomic data types, operations, and memory ordering constraints
libboost-chrono-dev - C++ representation of time duration, time point, and clocks (default version)
libboost-chrono1.58-dev - C++ representation of time duration, time point, and clocks
libboost-chrono1.58.0 - C++ representation of time duration, time point, and clocks
libboost-chrono1.62-dev - C++ representation of time duration, time point, and clocks
libboost-chrono1.62.0 - C++ representation of time duration, time point, and clocks
libboost-chrono1.67-dev - C++ representation of time duration, time point, and clocks
libboost-chrono1.67.0 - C++ representation of time duration, time point, and clocks

... ...

有all,嘿嘿,总能碰上吧.

sudo apt-get install libboost-all-dev 

安装后

# 配置动态库 不知道是否必须
sudo ldconfig

# aptitude命令没有,需要apt-get 安装
aptitude search boost

前面带 i 的表示已经安装了。

测试

直接copy别人的代码

#include <iostream>
#include <string>
#include <boost/program_options.hpp>

namespace bpo = boost::program_options;
using namespace std;

int main(int argc, char const *argv[])
{
    //步骤1:构造选项描述器
    //选项描述起,其参数为该描述器名字
    bpo::options_description opts("all options");
    //选项存储器,继承自map容器
    bpo::variables_map vm;

    //步骤2:为选项描述器增加选项
    //其参数依次为:key,value的类型,该选项描述
    opts.add_options()
        ("filename", bpo::value<std::string>(), "the file name which want to be found")
        ("help", "this is a program to find a specified file");

    //步骤3:先对命令行输入的参数做解析,而后将其存入选项存储器
    //如果输入了未定义的选项,程序会抛出异常,所以对解析代码要用try-catch块包围
    try {
        //parse_command_line()对输入的选项做解析
        //store()将解析后的结果存入选项存储器
        bpo::store(bpo::parse_command_line(argc, argv, opts), vm);
    } catch(...) {
        std::cout<<"Input option not exsited."<<std::endl;
        return 0;
    }

    //步骤4:参数解析完毕,处理实际信息
    //count()检测该选项是否被输入
    if(vm.count("help")) { //若参数中有help选项
        //options_description对象支持流输出,会自动打印所有的选项信息
        std::cout<<opts<<std::endl;
    }
    if(vm.count("filename")) {
        //variables_map(选项存储器)是std::map的派生类,可以像关联容器一样使用,
        //通过operator[]来取出其中的元素,但其内部的元素类型value_type是boost::any,
        //用来存储不确定类型的参数值,必须通过模版成员函数as<type>()做类型转换后,
        //才能获取其具体值
        std::cout<<"find"<<vm["filename"].as<std::string>()<<std::endl;
    }
    if(vm.empty()) {
        std::cout<<"no options found"<<std::endl;
    }
    return 0;
}

编译时要加上库名字

g++ -o s main.cpp -lboost_program_options

使用效果

pi@raspberrypi:~/chen_DIR/weihua/myoptions $ ./s --help
all options:
  --filename arg        the file name which want to be found
  --help                this is a program to find a specified file

pi@raspberrypi:~/chen_DIR/weihua/myoptions $ ./s --filename s
finds

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

bitQ

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值