I am using Boost 1.33.0 with MinGW on Windows XP. I am using the following program_optins code to collect command line arguments: po::options_description desc("Options"); desc.add_options() ...[everyting defined in here works as advertised]... ;//add-options() // specify the single, required graph file positional parameter po::positional_options_description pd; pd.add("graph_file", 1); po::variables_map vm; po::store(parse_command_line(argc, argv, desc), vm); po::notify(vm); ... The above code is shamelessly lifted from the tutorial. Everything defined in desc.add_options() works including the "-h" alternative to "--help". However, two things fail. * vm.count("graph_file") returns 0 regardless of whether there are positional argument(s). * specifying an -x, --xx, --xx=n option where "x" or "xx" is not included in desc.add_options() causes store() to not return (the program simply stops). Am I missing something? Merrill
Merrill Cornish wrote:
// specify the single, required graph file positional parameter po::positional_options_description pd; pd.add("graph_file", 1);
po::variables_map vm; po::store(parse_command_line(argc, argv, desc), vm); po::notify(vm);
Perhaps I am missing something, but I don't see where pd is included in the call to po::store(). My own code includes the following line (I think you can follow the various variable names; I have a class holding all the option descriptions, here refrenced as "opts"): store(po::command_line_parser(argc, argv). options(opts.commandline). positional(opts.positional). run(), configmap); I think I found I had to use command_line_parser() and its more explicit syntax (rather than the easier parse_command_line()) when using positional arguments. Take care, Liam -- Liam Routt Ph: (03) 8344-1315 Research Programmer caligari@cs.mu.oz.au Computer Science, Melbourne University (or liam@routt.net)
Merrill Cornish wrote:
I am using Boost 1.33.0 with MinGW on Windows XP. I am using the following program_optins code to collect command line arguments:
[snip]
* vm.count("graph_file") returns 0 regardless of whether there are positional argument(s).
* specifying an -x, --xx, --xx=n option where "x" or "xx" is not included in desc.add_options() causes store() to not return (the program simply stops).
Am I missing something?
As Liam points out, you need to use command_line_parser and positional(...), which should resolve the first problem. However, I've just hit the second problem in my own program, the help formatter function is barfing. I'm using Visual Studio 2005 (still on beta 2) on Windows XP and in fact I would have assumed this crash was a bug in the beta, but if you're seeing similar crashage under MinGW too then that seems unlikely. Running it under the debugger shows an assertion failure in the string iterator's += overloading, which is called by the -= overloading, which is called by format_paragraph (line 377 in boost 1.33's options_description.cpp): string::const_iterator last_space = find(reverse_iteratorstring::const_iterator(line_end - 1), reverse_iteratorstring::const_iterator(line_begin - 1), ' ') .base(); (What's the deal with the reverse_iteratorstring::const_iterators there, is string::const_reverse_iterator nonstandard or unreliable?) Looking at the options_description code, I believe the offending calculation is "line_begin-1", which isn't valid since on the first iteration line_begin will normally be equal to par.begin() (and so will typically only work on string implementations where iterators are pointers). In other words, it appears to be an off-by-one bug in the iterator constructions in format_paragraph. Cheers, Will -- Will Bryant http://carcino.gen.nz/ will@core-dev.co.nz +64 21 655 443
participants (3)
-
Liam Routt
-
Merrill Cornish
-
Will Bryant