Questions tagged [boost-program-options]

Boost.Program_options is a C++ library that allows program developers to obtain (name, value) pairs from the user via conventional methods such as command line and config file.

Boost.Program_options is a C++ library that allows program developers to obtain program options, that is (name, value) pairs from the user, via conventional methods such as command line and config file.

Why would you use such a library, and why is it better than parsing your command line by straightforward hand-written code?

  • It's easier. The syntax for declaring options is simple, and the library itself is small. Things like conversion of option values to desired type and storing into program variables are handled automatically.
  • Error reporting is better. All the problems with the command line are reported, while hand-written code can just misparse the input. In addition, the usage message can be automatically generated, to avoid falling out of sync with the real list of options.
  • Options can be read from anywhere. Sooner or later the command line will be not enough for your users, and you'll want config files or maybe even environment variables. These can be added without significant effort on your part.
381 questions
0
votes
1 answer

boost::program_options custom validate and default value

I am using boost::program_options to parse arguments. Because I cannot break compatibility I need to allow specifying some arguments multiple times. I need to do it for example for strings (last one wins) or for booleans (every occurence switches…
Martin
  • 165
  • 1
  • 15
0
votes
2 answers

How should I exit a C++ program cleanly after printing the CLI help message from a function?

I'm trying to figure out the best way to exit my program cleanly after printing the CLI help information in my program. Currently it looks like this. int main(int argc, *char[] argv) { try { std::string settings_file = process_args(argc,…
Kevin Glasson
  • 408
  • 2
  • 13
0
votes
0 answers

boost::program_options: parsing multi-valued options in ini-files in a single name-value pair

if I specify ip_addresses=monkeys ip_addresses=baboons parse_config_file creates multiple strings resulting in a std::vector< std::string> as output. I want to list multiple strings on a single line. ip_addresses=monkeys, baboons The result is a…
Hassan Syed
  • 20,075
  • 11
  • 87
  • 171
0
votes
1 answer

Keeping preset (non-default) values when calling boost parseOptions

In my project I've got some internal config structures containing options registration using default values (let's say Config.x=0, Config.y=0), those values are not modifable for a client. Sometimes users of my application want to modify default…
mtszkw
  • 2,717
  • 2
  • 17
  • 31
0
votes
0 answers

Boost Program Options short name issue

I am using boost/program_options for my CLI application. I am reading a variable named name from the user. The variable CLI option called --name or -n for short name. When i execute ... --name val ... the variable is set to val (as expected). But…
Saar peer
  • 817
  • 6
  • 21
0
votes
1 answer

Boost program options - pass arg name from function result

I've reproduced my problem based on the example from the official tutorial. #include #include #include namespace po = boost::program_options; using namespace std; const char* withAlias(const char*…
Giora Guttsait
  • 1,279
  • 15
  • 29
0
votes
1 answer

boost program options config.hpp not found, Mac Xcode 8.3

Trying to compile simple example program with boost::program_options. The suggested include directive for the lib is #include I noticed the hard path to boost/program_options.hpp (relative to root folder)…
bigswifty
  • 127
  • 2
  • 10
0
votes
4 answers

dynamic configuration with boost program_options

Is there a way to load a dynamic INI file like the one below. [basic] number_of_servers=3 [server1] ip=10.20.30.40 password=sdfslkhf [server2] ip=10.20.30.41 password=sdfslkhf [server3] ip=10.20.30.42 password=sdfslkhf Here the idea is that…
ϹοδεMεδιϲ
  • 2,790
  • 3
  • 33
  • 54
0
votes
1 answer

ORBInitialHost parameter

Assume I have a java server which uses corba. When I start it with command java server -ORBInitialHost localhost -ORBInitialPort 1111 I pass parametres -ORBInitialHost localhost -ORBInitialPort 1111. Will I have 2 elements of array String [] args…
maks
  • 5,911
  • 17
  • 79
  • 123
0
votes
1 answer

undefined reference to boost::program_options in vowpalwabbit compilation, ubuntu 16.04

I am trying to install vowpal_wabbit in ubuntu 16.04. Error : ./libvw.a(search.o): In function `Search::setup(vw&)': search.cc:(.text+0xa5f8): undefined reference to `boost::program_options::options_description::options_description(std::string…
Kapil Gupta
  • 7,091
  • 5
  • 16
  • 25
0
votes
1 answer

boost::bad_any_cast: failed conversion using boost::any_cast

I am using boost V1.53 program_option like this.. #include #include #include #include #include "linked_list.h" #include #include "stdList.h" #include "vector.h" #include "set.h" #include "AVL.h" #include…
Christine Zhu
  • 77
  • 1
  • 7
0
votes
0 answers

boost program option generate error without any reason

I am using Boost 1.62.0 on windows with Visual studio 2013 and pre compiled libraries. I have this sample code: #include "boost/program_options.hpp" #include "boost/filesystem.hpp" #include namespace po = boost::program_options; int…
mans
  • 17,104
  • 45
  • 172
  • 321
0
votes
1 answer

`boost::program_options` cannot use `store` twice on `variables_map`

I'm trying to edit a boost::program_options::variables_map to add implied option according to the first positional option. However, using po::store doesn't work a second time when using it on a boost::variables_map. Here is a minimal example that…
Lærne
  • 3,010
  • 1
  • 22
  • 33
0
votes
1 answer

Why boost::program_options::bool_switch is not behaving like I expect?

Code below uses po::bool_switch(&flag) in hope of automatically assigning the correct value to flag. My compile command is clang++ -std=c++11 test.cpp -o test -lboost_program_options So I run the program with ./test -h which shows no help…
user1587451
  • 978
  • 3
  • 15
  • 30
0
votes
1 answer

Which C++ language feature is repeating parentheses after function call?

I am using the boost::program_options library and the code below is used to create a description of the options and add options to it: po::options_description opts("SendFile Options"); opts.add_options()("help,h", "Print this help message") …
user3096803