I have the following boost :: program_options program.
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; }
However, when I specify --mingw="stuff" on the command line, I find that it was rejected. After issuing the --help command, it seems that only the first option option in the list was actually registered with opts - although binding it this way is what the tutorial recommends.
What happens with this simple sample program? This is mainly directly from the textbook.
Puppy source share