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
0 answers

Ambiguous option with boost because the parameter name begins with the same string

Here is my problem: Using program_options from lib BOOST (C++), I have this weird behavior: #include #include using namespace boost; namespace po =…
Guillaume
  • 135
  • 1
  • 8
0
votes
1 answer

Copying boost::program_options::parsed_options

Consider this function: po::parsed_options ParserClass::parseOptions(int argc, char *argv[]) { return po::command_line_parser(argc, argv) .options(desc) .positional(pos) .run(); } desc and pos are member…
user2373682
0
votes
1 answer

boost::program_options: how to make validation_error with the full option name and more informative

When I'm using boost::program_options, after throwing out validation_error, the error message does not display the full option name. I have the following simple example source code, compiled with g++ -std=c++11 test.cpp -lboost_program_options. This…
xuhdev
  • 8,018
  • 2
  • 41
  • 69
0
votes
1 answer

c++ boost program options always giving default value

I'm struggling to get boost program options to work properly. I need to be able to start my program from the terminal window (Linux) with an optional argument that takes a value. No matter what I did, this would not work; no matter what value I…
ppyvabw
  • 141
  • 8
0
votes
0 answers

boost::program_options v1.59 breaks API compatibility

Since v1.59 on boost::program_options, if you specify an implicit_value (say 3) for a command line option, then this command line: ./myprogram --myoption 5 will no longer parse and assign myoption the value of 5, instead it's assigned myoption the…
Martin
  • 9,089
  • 11
  • 52
  • 87
0
votes
0 answers

template compile error - string not recognized as string in boost::program_options::variables_map.at()?

I am completely out of ideas why the following example template will fail to compile on C++11 (gcc 4.9.2). For some reason, compiler requires me to call string() on already a string object that is being passed as variables_map.at() parameter. Note,…
Marcin L
  • 73
  • 10
0
votes
1 answer

Link with a boost library fails when compiling with CUDA nvcc, succeeds with gcc

I'm trying to build an executable from just the following code (say it's in the file kt.cu): #include int main(int argc, char** argv) { boost::program_options::options_description options("Options"); return…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
0
votes
1 answer

How to pass program options in boost without argument name having all other options beeing fully avalible

I was wondering how is it possible to pass program options in boost without giving argument name like program.exe var1 instead of program.exe --arg1 var1. However I know how to handle this without boost lib with obtaining just argv[1]. There are two…
user5351148
0
votes
1 answer

program_options - "invalid option value" when has to read array from file

I'm trying to read an array from a configuration file but it shows the message: " in option 'PARAM_ARRAY': invalid option value ". The topic doesn't helps me because it reads the array from command line. The code (only important lines) is something…
0
votes
0 answers

Doubts using boost::program_options

I'm using boost::program_options in one of my applications. With it, I fill almost all of my classes parameters. Since I need to pass "options" to different classes, I was declaring variable_map in the global scope and passing it as extern among…
Filippo Lauria
  • 1,965
  • 14
  • 20
0
votes
1 answer

Boost:;program_options 1.49 - can't link with -lboost_program_options

I'm attempting my first use of Boost anything so I thought I'd start with program_options. I'm developing on a Raspberry Pi running Debian Wheezy. I started by "apt-get install libboost1.49-all" and everything seemed to install correctly. I can…
Kelly Beard
  • 684
  • 1
  • 8
  • 20
0
votes
1 answer

Boost program options and "one of" relationships

I want to only allow one of a number of options, i.e. --frequency= or --wavelength= or --energy=, but not more than one of them. Is there a way to do this with boost program options?
Andrew Spott
  • 3,457
  • 8
  • 33
  • 59
0
votes
1 answer

How to use boost program_options to read an integer array?

I am using Ubuntu and boost v1.50. Previously I used boost program_options to feed a set of options into a program like so: #!/bin/bash ./prog --arg1 1 --arg2 "2" --arg3 {1,2,3} --arg4 {1,2} --arg5 5 So I am dealing with a mix of single integers,…
Oscillon
  • 165
  • 3
  • 13
0
votes
0 answers

boost program_options with WinMain

This is my main.cpp header #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 int WINAPI WinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd ) #else int main(int argc, char* argv[]) #endif I want to use program_options but…
Vinz243
  • 9,654
  • 10
  • 42
  • 86
0
votes
2 answers

Input Stream Operator lookup order with Boost.Program_options

I have an enumeration class and a corresponding input stream operator in the namespace fw::example. #include #include #include namespace fw { namespace example { enum class Booleans { kFalse = 0, kTrue =…
Florian Wolters
  • 3,820
  • 5
  • 35
  • 55