[program_options] bad_any_cast problem with strings in variables_map
(apologies if this comes through multiple times, I'm having subscription issues) I'm a novice Boost user attempting to use program_options. As far as I can tell from the docs and sample code, this should work (only relevant code included): po::options_description desc("Allowed options"); desc.add_options() ("client", po::value<string>(), "set client name") ("test", "tool test mode, dump command line options only") ; po::variables_map vm; po::store(po::parse_command_line(ac, av, desc), vm); po::notify(vm); if (vm.count("test")) { if (vm.count("client")) cout << "client set to " << vm["client"].as<string>() << "\n"; else cout << "client not set\n"; } However, when I run with "--client testclient --test", the as<string> call generates a bad_any_cast exception. What am I missing or misunderstanding? -- Jeffrey Schmidt, senior software architect MultiAd(r) Creator and Creator Server jschmidt@multiad.com
I just tried your code and it works fine with vc8 and boost 1.33.1. What system/compiler/boost are you using? Chris
On 6/22/07, Chris Weed
I just tried your code and it works fine with vc8 and boost 1.33.1.
What system/compiler/boost are you using?
Mac OS X (10.4.10, PPC) using Apple's gcc 4.0.1, boost 1.34.0. Since this does work properly in other environments, I'm suspecting a library problem... is there a caveat to building boost libs on my platform that I should be aware of, that the standard configure-and-make process doesn't handle?
The regression test system on the following link seems pretty similar:
http://tinyurl.com/2xudzb
I think you might need to post a full code example that reproduces
this and compile lines you run to build this.
I don't have a PPC system, but I recall a coworker setting the
compiler to darwin in boost-build if you are using that. Are there
pre-built binaries that you might be able to use for the boost libs?
Chris
On 6/24/07, Jeffrey Schmidt
On 6/22/07, Chris Weed
wrote: I just tried your code and it works fine with vc8 and boost 1.33.1.
What system/compiler/boost are you using?
Mac OS X (10.4.10, PPC) using Apple's gcc 4.0.1, boost 1.34.0. Since this does work properly in other environments, I'm suspecting a library problem... is there a caveat to building boost libs on my platform that I should be aware of, that the standard configure-and-make process doesn't handle? _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Well... I'm pretty certain I didn't do anything differently this time around, but after a boost library rebuild it is working as advertised.
participants (2)
-
Chris Weed
-
Jeffrey Schmidt