|
Boost Users : |
Subject: [Boost-users] [program_options] VM object unable to store the values of options
From: Wenjing Jia (wejia_at_[hidden])
Date: 2009-02-05 18:47:20
(Apologies if this message has come out for more than once, as I had
problem with authorization and is unsure when the message is able to be
seen by boost users!)
Hi,
I'm met a very weird thing when using the Boost.Program_options
library. Somehow, the variable-map(VM) object is unable to store values
of options which are fed in from the command line. I've been stuck in
this stupid problem for two days and cannot find any clue about it. Can
someone please give me a hint?
I'm using the Visual Studio 2005 on Windows XP SP3 to compile some
examples provided in Boost.Program_options Tutorial. The boost library
was installed using the boost_1_34_1 installer. However, no matter what
value I input to any option, the variable-map object "vm" I defined is
unable to store it and output it correctly.
For instance, I followed the instructions in the Tutorial of the
Boost.Program_options and compiled the first simplest possible example
"example/first.cpp". I then went to "start" of Windows XP and Run "cmd",
then run: "first --compression 10". The output is always "Compression
level was set to -858993460." regardless of what value I type after the
"--compression". Below is the full codes of the program (copied from the
"example/first.cpp"):
-------------------------------------------------------------------------------
#include <boost/program_options.hpp>
namespace po = boost::program_options;
#include <iostream>
#include <iterator>
using namespace std;
int main(int ac, char* av[])
{
try {
po::options_description desc("Allowed options");
desc.add_options()
("help", "produce help message")
("compression", po::value<int>(), "set compression level")
;
po::variables_map vm;
po::store(po::parse_command_line(ac, av, desc), vm);
po::notify(vm);
if (vm.count("help")) {
cout << desc << "\n";
return 1;
}
if (vm.count("compression")) {
cout << "Compression level was set to "
<< vm["compression"].as<int>() << ".\n";
} else {
cout << "Compression level was not set.\n";
}
}
catch(exception& e) {
cerr << "error: " << e.what() << "\n";
return 1;
}
catch(...) {
cerr << "Exception of unknown type!\n";
}
return 0;
}
-------------------------------------------------------------------------------
I also tried on the other examples mentioned on that web page, such as
"example/options_description.cpp". When I type:
"options_description --optimization 4 -I foo a.cpp",
the output is:
"Include paths are:
Input files are:
Optimization level is -858993460".
That is the input values are not taken and stored by the vm object.
Why such a simple example won't work on my machine!?
Your suggestion would be most appreciated!
Many thanks in advance!
Wenjing
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net