C++ Boost程序选项-解析命令行时崩溃
我有以下boost::program\u options程序C++ Boost程序选项-解析命令行时崩溃,c++,boost,boost-program-options,C++,Boost,Boost Program Options,我有以下boost::program\u options程序 boost::program_options::options_description opts("Allowed options"); opts.add_options() ("help", "produce help message"), ("mingw", boost::program_options::value<std::string>(), "Set the install path for M
boost::program_options::options_description opts("Allowed options");
opts.add_options()
("help", "produce help message"),
("mingw", boost::program_options::value<std::string>(), "Set the install path for MinGW"),
("triple", boost::program_options::value<std::string>(), "Set the target triple"),
("output", boost::program_options::value<std::string>(), "Set the output file"),
("input", boost::program_options::value<std::vector<std::string>>(), "Set an input file."),
("include", boost::program_options::value<std::vector<std::string>>(), "Set an include path.")
;
boost::program_options::positional_options_description posopts;
posopts.add("input", -1);
boost::program_options::variables_map vm;
try {
boost::program_options::store(boost::program_options::command_line_parser(argc, argv).options(opts).positional(posopts).run(), vm);
} catch(std::exception& e) {
std::cout << e.what();
std::cin.get();
}
boost::program_options::notify(vm);
if (vm.find("help") != vm.end()) {
std::cout << opts << "\n";
std::cin.get();
return 1;
}
// Actual program logic
boost::程序选项::选项描述选项(“允许选项”);
opts.add_options()
(“帮助”,“生成帮助消息”),
(“mingw”,boost::program_options::value(),“设置mingw的安装路径”),
(“三重”,boost::program_options::value(),“设置目标三重”),
(“输出”,boost::program_options::value(),“设置输出文件”),
(“输入”,boost::program_options::value(),“设置输入文件”),
(“包含”,boost::program_options::value(),“设置包含路径”。)
;
boost::program_options::positional_options_description posopts;
posopts.add(“输入”,-1);
boost::程序选项::变量映射虚拟机;
试一试{
boost::program_options::store(boost::program_options::command_line_解析器(argc,argv).options(opts).positional(posopts).run(),vm);
}捕获(标准::异常&e){
std::cout查看教程,我没有看到选项之间的逗号。例如:
desc.add_options()
("help", "produce help message") // no comma here!
("compression", po::value<int>(), "set compression level")
;
desc.添加选项()
(“帮助”,“生成帮助消息”)//这里没有逗号!
(“压缩”,po::value(),“设置压缩级别”)
;
尝试删除每个选项末尾的逗号。我在open SUSE Leap 42.2的boost_1_63上也遇到了同样的问题。使用/b2重新编译所有boost lib…--build type=complete并重新安装时,问题不再出现。希望这将至少对你们中的一些人有所帮助。哦,该死的家伙。这是一个错误平心而论,boost确实突破了合理语法的限制。@JoeZ,而且它经常也超越了这些限制:用--build type=complete来编译boost库会生成所有版本(多线程、调试等)我想,当安装了所有版本的程序_options lib后,会使用最合适的版本进行链接,因此程序_options不会在解析命令行时崩溃。可能不需要重新编译所有的boost lib,但我目前没有时间探究崩溃的确切原因。