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
3
votes
1 answer

RAII with boost boost::program_options and options_description

Following an example on net From this answer I came up with this: int server_port; auto value_port = new po::typed_value(&server_port); //<-- Really?? value_port->value_name("port"); po::options_description…
bolov
  • 72,283
  • 15
  • 145
  • 224
3
votes
2 answers

How to parse comma separated values with boost::program_options?

I need to parse cmd like -value=str1,str2,str3 using boost::program_options. I've found exactly the same question but it's not working anymore (with boost 1.55 and 1.56). I've tried to define my own class and mapper but no luck: namespace po =…
4ntoine
  • 19,816
  • 21
  • 96
  • 220
3
votes
1 answer

Parse prefix arguments with boost::program_options?

I need to parse argument with prefix with boost::program_options like -O1 / -O2 / -O3, so -O is prefix followed by optimization level as number. It's declared using LLVM CommandLine support like that and i need to like that: cl::opt
4ntoine
  • 19,816
  • 21
  • 96
  • 220
3
votes
1 answer

Statically linking boost program_options

One of the few Boost libraries that are not header only (therefore need to be compiled separately) is program_options. I need to run a program that I compile on my PC in a cluster that has no Boost installed. I don't have administrative rights to…
a06e
  • 18,594
  • 33
  • 93
  • 169
3
votes
1 answer

How to use sections in a boost program options config file

This is obviously a fairly simple question, as no one else has had this issue such as this with the library. When I run my program however, boost returns the error "Unrecognised Option Settings.Directoy" However I have defined this in my code and…
user1591117
  • 287
  • 2
  • 5
  • 13
3
votes
0 answers

Repeat same option with multitoken

Is it possible to repeat the same option with multitoken? For instance, is it possible from this line : -t algo1 5 7 9 -t algo2 6 2 to obtain something like the following vector of vector? ___ ___ | ___ | ___ | | | v v ___ …
benlaug
  • 2,691
  • 2
  • 17
  • 15
3
votes
2 answers

How to parse boolean option in config file

Using boost 1_55, I have a bool_switch() option, which is defined as: bpo::options_description opts; opts->add_options() ("foo", bpo::bool_switch(), "Enable foo."); opts_map = new bpo::variables_map; And it is parsed on the command line…
user9645
  • 6,286
  • 6
  • 29
  • 43
3
votes
1 answer

boost::program_option::store throws exception when option string contains mixed language characters

I have simple code that works perfectly well with input option contains just ASCII characters, but throws an exception with error message of "error: character conversion failed". Is there a solution? Background info: 1. Compiler and OS: VC++2012…
James
  • 31
  • 2
3
votes
1 answer

boost::program_options overloaded validate is ambiguous

I am trying to parse a list input from the command line. My class is derived from vector The compiler complains about a overloaded validate being ambiguous. I can see why, but do not know how to solve this issue. Please help. Below is a minimal…
3
votes
1 answer

Exporting arguments from boost program options to doxygen

I am writing a tool with command line options coordinated by boost program options. The API is well documented with Doxygen, but I would like Doxygen to also document the command line options for the tools extracting the information from the boost…
Carneiro
  • 3,479
  • 5
  • 24
  • 36
3
votes
1 answer

Handling unknown commands with the boost command line parser

I want to handle (note, not use in any way) the unknown options. So there is this: http://www.boost.org/doc/libs/1_54_0/doc/html/program_options/howto.html#idp123440592 That can be used to collect and use any unknown options, so I could…
IdeaHat
  • 7,641
  • 1
  • 22
  • 53
3
votes
1 answer

need a command-line parser to fit my requirements

It's a question about C/C++ command line parser. I used the command line parsers provided in glib and Boost, but I found them not satisfying. I have two special requirements: multiple values following one key, so that I can use file glob on command…
jiandingzhe
  • 1,881
  • 15
  • 35
3
votes
1 answer

Why do I always get default values when passing positional arguments?

I'm trying to familiarize myself with boost::program_options, and I'm running into a problem with positional arguments. Here's my main function, where I set options passed through the command line. Please note that po is a namespace alias for…
Louis Thibault
  • 20,240
  • 25
  • 83
  • 152
3
votes
2 answers

Is it possible to use Boost Program Options without RTTI?

I would like to disable RTTI in a project of mine. However, this project uses Boost Program Options which itself depends on Boost Any which does not support -fno-rtti. I was wondering if there was any solution to use Boost Program without RTTI ? By…
Baptiste Wicht
  • 7,472
  • 7
  • 45
  • 110
3
votes
2 answers

What is the Preferred Cross-platform 'main' Definition Using boost::program_options?

I'm trying to develop a cross-platform application using C++ with boost. I typically program in a *nix environment, where I've always defined 'main' as follows: int main( const int argc, const char* argv[] ) { ... } For this application, I'm…
Adam Holmberg
  • 7,245
  • 3
  • 30
  • 53