boost-program-options

Cannot find C++ library when linking, error compliling the `boost::program_options` example

别来无恙 提交于 2019-12-05 10:44:13
问题 I am trying to compile the multiple_sources.cpp to compile on my computer. I am running Xubuntu Lucid Lynx fully updated. It will compile without issue with g++ -c multiple_sources.cpp but when I try to link and make an exectuable with g++ multiple_sources.o I get: multiple_sources.cpp:(.text+0x3d): undefined reference to `boost::program_options::options_description::m_default_line_length' multiple_sources.cpp:(.text+0x87): undefined reference to `boost::program_options::options_description:

How does one extract the sequence of parsed options using Boost Program Options?

纵然是瞬间 提交于 2019-12-05 10:42:30
I'm building a graph generator using Boost Graph and Program Options. There are, for example, two types of components C and W, each with 1 source, 1 sink and some additional parameters to specify topology in between. I'd like to be able to stitch them together in the sequence provided by the order of the command line arguments. For example: ./bin/make_graph -c4,5,1 -w3,3 -c3,1,2 Should create a graph resembling the following: C -- W -- C But: ./bin/make_graph -c4,5,1 -c3,1,2 -w3,3 Should create a graph resembling the following: C -- C -- W Using boost::program_options, I was unable to

Boost Program Options won't work with GLIBCXX_DEBUG

你。 提交于 2019-12-05 02:29:22
I have the following sample code: #include <iostream> #include <boost/program_options.hpp> int main ( int ac, char *av[] ) { // Declare the supported options. boost::program_options::options_description desc("Allowed options"); desc.add_options()("help", "produce help message"); boost::program_options::variables_map vm; boost::program_options::store(boost::program_options::parse_command_line(ac, av, desc), vm); return 0; } It compiles fine using e.g. g++ test.cpp -lboost_program_options . However if I try to activate GCC bounds checking with the call g++ test.cpp -lboost_program_options -D

boost::program_options and multiple sections in ini-file

雨燕双飞 提交于 2019-12-05 00:30:20
问题 I'm trying to get boost::program_options to read a ini file with multiple sections: [slave] address=localhost port=1111 [slave] address=192.168.0.1 port=2222 Is there any solution? Thanks in advance! 回答1: There are a few solutions to this problem. While it may initially appear that this should be an easy task, it is often fairly involved. This is because sections are roughly equivalent to namespaces; sections are not equivalent to objects. [slave] address=localhost port=1111 [slave] address

How to accept empty value in boost::program_options

核能气质少年 提交于 2019-12-05 00:29:18
I'm using boost::program_options library to process command line params. I need to accept a file name via -r option, in case if it is empty (-r given without params) I need to use stdin. desc.add_options() ("replay,r", boost::program_options::value<std::string>(), "bla bla bla") In this case boost wouldn't accept -r without params and throw an exception. default_value () option does not work as well as it would make library return value even if user didn't give -r option. Any ideas how to work around? Please use the implicit_value method, e.g desc.add_options() ("replay,r", po::value<std:

How to use boost::program_options to accept an optional flag?

喜夏-厌秋 提交于 2019-12-04 16:07:50
问题 I need to implement an optional flag, say -f / --flag . Since this is a flag, there is no value associated. In my code I only need to know whether the flag was set or not. What's the proper way to do this using boost::program_options? 回答1: A convenient way to do this is with the bool_switch functionality: bool flag = false; namespace po = boost::program_options; po::options_description desc("options"); desc.add_options() ("flag,f", po::bool_switch(&flag), "description"); po::variables_map vm;

Can Boost Program_options separate comma separated argument values

我们两清 提交于 2019-12-04 13:39:12
If my command line is: > prog --mylist=a,b,c Can Boost's program_options be setup to see three distinct argument values for the mylist argument? I have configured program_options as: namespace po = boost::program_options; po::options_description opts("blah") opts.add_options() ("mylist", std::vector<std::string>>()->multitoken, "description"); po::variables_map vm; po::store(po::parse_command_line(argc, argv, opts), vm); po::notify(vm); When I check the value of the mylist argument, I see one value as a,b,c . I'd like to see three distinct values, split on comma. This works fine if I specify

skipping unknown options without throwing with boost program options

人盡茶涼 提交于 2019-12-04 13:30:27
These days I am playing with Boost program options for reading INI files. The code I have throws an exception once in the file there is a line with an unknown option. Do you know whether is possible and how to let the code below read the whole file? I want to skip the unknown options without throwing so that I can read all possible values. Thanks a lot AFG namespace pod = boost::program_options; pod::options_description options("Options"); std::string myArgValue; options.add_options() ("SECT_A.Option_A", pod::value<int>()->default_value(1), "xxx") ("SECT_B.Option_B", pod::value<std::string>(

boost program_options multiple values problem

北城以北 提交于 2019-12-04 11:15:49
问题 So I'm working off one of the examples for Boost program_options library, and I wanted to try setting a default value for one of the multiple-values/ vector-values, but it doesn't seem to work. As I think is suggested here to work. What I've modified is on about line 40: po::options_description config("Configuration"); config.add_options() ("optimization", po::value<int>(&opt)->default_value(10), "optimization level") ("include-path,I", o::value< vector<string> >()->default_value(vector

Using '--' as end-of-options marker with boost::program_options

£可爱£侵袭症+ 提交于 2019-12-04 10:11:54
问题 The traditional way of indicating the end of options for command line programs is with the option -- . How can I get boost::program_options to recognize this as an option and accept the rest of the command line as positional arguments? The following doesn't work: namespace po = boost::program_options; po::positional_options_description posOpts; posOpts.add("keywords", 1); posOpts.add("input", 1); std::vector<std::string> final_args; po::options_description desc("Allowed Options"); desc.add