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
1
vote
2 answers

buffer overflow with boost::program_options

I have a problem using boost:program_options this simple program, copy-pasted from boosts' documentation : #include int main( int argc, char** argv ) { namespace po = boost::program_options; …
f4.
  • 3,814
  • 1
  • 23
  • 30
1
vote
2 answers

linking error for boost::program_options

I can't figure out a linking error to use boost::program_options. Here's a sample c++ code: # sample_code.cpp #include int main() { boost::program_options::options_description description("Test"); } I've also…
Reza Toghraee
  • 1,603
  • 1
  • 14
  • 21
1
vote
2 answers

Read relative file path with Boost Program options

I'm working on a command line tool that can read options from: The command line arguments An optional configuration file I used Boost Program Options to read those options and it works mostly fine. My code is like so: namespace po =…
ereOn
  • 53,676
  • 39
  • 161
  • 238
1
vote
1 answer

Best way of handling level 2 commands with Boost ProgramOptions

I'm interested in having a single executable that takes level 2 commands on the command line - kind of like git commit and git add are their own separate commands within one EXE. So my question is: is there any way of simplifying this with…
Dmitri Nesteruk
  • 23,067
  • 22
  • 97
  • 166
1
vote
1 answer

Boost program options pair value

I'm observing a curious behavior of the boost::program_options::value function with STL classes. I often need to provide arguments to programs in pairs, e.g. file names with short labels, but the boost::program_options::value function seems not to…
SU3
  • 5,064
  • 3
  • 35
  • 66
1
vote
1 answer

Can I parse together guessable and non-guessable options with Boost::program_options?

I have some options that are quite verbose like -length -strength and I would like to allow guessing for them, so that the user can cut their names. On the other hand some options have short names that include each other like -K1 -K10 and for those…
DarioP
  • 5,377
  • 1
  • 33
  • 52
1
vote
1 answer

Selecting option group according the first option

I have implemented an application(lets call it "app") that performs 2 types of tasks, TA and TB. The command line options differs for each type of task. That's why I have decided that the user will specify the type of task with a "command": app…
Raydel Miranda
  • 13,825
  • 3
  • 38
  • 60
1
vote
2 answers

Boost 1.55.0 Program Options Issues

Decided to finally bite the bullet and download, build, and link in Boost after having failed to find a reasonable ini file reading method over the last few months. After creating a test project to see how the process worked I am stuck with the…
Geowil
  • 624
  • 1
  • 12
  • 36
1
vote
1 answer

Parsing options with boost

I have code that is crashing: if(argc<2) { printf("Too few arguments\n"); } else if(argc>=2) { namespace po = boost::program_options; po::options_description desc("Options"); desc.add_options() …
CppMonster
  • 1,216
  • 4
  • 18
  • 35
1
vote
1 answer

Unrecognized error in boost library

I got this code from a book (Boost C++ Application Development Cookbook) and I tried running it, it compiled with g++ but when I try running it, it gives me this error "terminate called after throwing an instance of…
JSamson
  • 31
  • 6
1
vote
1 answer

Can't link to lboost_program_options

I am trying to compile my project with following g++ command: g++ -Wall -o mdaemon mdaemon-Mdaemon.o mdaemon-Rm.o mdaemon-Share.o mdaemon-SuperDaemon.o mdaemon-wmxver.o -pthread -L/home/sunshyn/wmx_simmode/src/../cots/lib/i686-redhat-linux-gnu…
Sunshyn
  • 43
  • 5
1
vote
1 answer

Boost Program Options and validate function

I am trying to write my own validate function for program boost options. However, I am getting: " terminate called after throwing an instance of 'boost::exception_detail::clone_impl >' what(): boost::bad_any_cast: failed conversion using…
user1703589
  • 41
  • 1
  • 5
1
vote
1 answer

Boost program options: multiple options for the same value

I am trying to get input options using boost::program_options. I would like to have two source of options one from command line and another from file but I also want to have different option names for the same value. commandLine.add_options() …
Ashkan
  • 1,050
  • 15
  • 32
1
vote
1 answer

Boost program option: force "="

I'm using boost::program_options, and this question is merely aesthetic. How can I force a std::string option (or better, all options) to use only long form with "="? Right now, all I see is "=" being forced on my int option, while the string isn't…
senseiwa
  • 2,369
  • 3
  • 24
  • 47
1
vote
1 answer

unresolved symbols while linking boost program options

A user of my project reported this error to me. I cannot reproduce it on my computer or my lab's server, so I ask it here. The project uses CMake to generate build environment. It uses the FindBoost utility (provided with CMake) to find Boost…
jiandingzhe
  • 1,881
  • 15
  • 35