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

Single-token and multi-token positional options with boost::program_options

I am writing a program that would receive as parameters a filename followed by multiple strings. Optionally it could take a -count argument; ./program [-count n] ... This is the code I wrote: …
0
votes
1 answer

Hang using Boost Program Options under Cygwin

I've been porting a C++ program from Linux to Cygwin on Windows, and am having trouble with Boost Program Options (Boost 1.43). The program compiles and runs fine on Linux (Boost 1.44), but hangs under Cygwin: /* prints */ std::cout << "positional…
0
votes
1 answer

MinGW exe reports libgcc_s_seh-1.dll not found even with -static-libgcc

I'm cross compiling boost::program_options on Linux for Windows using CMake. In CMake I specified set(Boost_LIBRARIES /usr/local/win64/lib/libboost_program_options.dll) set(Boost_INCLUDE_DIR…
0
votes
1 answer

In Boost Program Options, how can I tell if an option with default is specified?

I'm writing a program which takes a size, a redundancy, and some plaintext, and outputs a code of the plaintext. I'd like the size and redundancy used for encoding to be computed as follows: If neither size nor redundancy is specified, the…
Pierre Abbat
  • 485
  • 4
  • 10
0
votes
0 answers

Create C++ 'argv' equivalent from vector of strings

I have some legacy C++ code that accepts input parameters. It is in the following format: int main(int argc,char* argv[]) { parse_args(argc,argv); return 0; } The inputs had to be specified in the following format: $ ./a.out -f sample.txt…
0
votes
2 answers

Boost Linker Issues

I am using the Boost library and I am having some linker issues. Currently my code is outputting this: Undefined symbols for architecture x86_64: "boost::program_options::to_internal(std::__1::basic_string
Rahul
  • 181
  • 1
  • 2
  • 13
0
votes
1 answer

In boost::program_options, can positional arguments be skipped when already specified explictly?

I'm using boost program_options to parse command line arguments, and I'm trying to make use of the positional arguments feature. The goal is to make typing "--tool" optional, and to assume that the first argument is the tool if "--tool" isn't typed…
Wriiight
  • 21
  • 3
0
votes
1 answer

I'm passing an std::string to a boost function that takes a const reference to that type, but the value is mutated

I'm passing an std::string to a function imported from boost-program-options dll. The function takes one parameter and it's a const reference to a string. However, the value that the function receives is different from what I pass. Here's the…
0
votes
0 answers

Boost.program_options generates too big executable file

Compiling a test module boost_program_options_test.cpp that is almost the same as boost_1_72_0\libs\program_options\example\first.cpp: >g++ -std=c++11 -Wall -g -o boost_program_options_test.exe -ID:\temp\boostinst-01\boost_1_72_0\…
Nick Legend
  • 789
  • 1
  • 7
  • 21
0
votes
1 answer

Add boost program_options as a git submodule and build an executable with its sources

I have a small project that uses boost::program_options. I want to add this (only this) library to my project as a git submodule and build my executable using its sources. I have already done the git submodule part (git submodule add…
Dan
  • 2,452
  • 20
  • 45
0
votes
1 answer

Writing testable code - a basic_istream factory within lambda functions and unique_ptr

Introduction This is a request for an assessment of my approach, in the context of modern C++ features that I'm not confident with yet, like lambda functions and basic_istream. I have a short list of specific questions at the end, all of which are…
davidA
  • 12,528
  • 9
  • 64
  • 96
0
votes
1 answer

How to use options for both command line and hierarchical config file with Boost Program_Options

Imagine I have a program that takes the following command-line option: $ prog1 --foo 1 I also have a configuration file that is in this hierarchical format, with the foo parameter within the prog1 scope: [prog1] foo = 42 My understanding of…
davidA
  • 12,528
  • 9
  • 64
  • 96
0
votes
1 answer

Why does parse_config_file set failbit on a stream?

This minimal program uses boost::program_options to parse a stringstream. Strangely, after parsing, the stream is not in a "good" state anymore and both failbit and eofbit are set. #include #include #include…
francesco
  • 7,189
  • 7
  • 22
  • 49
0
votes
1 answer

Command line argument not stored (using boost)

I want to store a command line value into a variable. Here's my complete code: #include #include int main(int argc, char *argv[]) { int nselect = 100; boost::program_options::options_description…
highBandWidth
  • 16,751
  • 20
  • 84
  • 131
0
votes
1 answer

Arguments without dashes using boost::program_options

I am writing a new implementation of existing software (clean room implementation so no access to old code) and as well as a new command line interface I need to emulate the old interface for compatibility with existing workflows. I am choosing…
PTooley
  • 383
  • 3
  • 11