Boost logo

Boost Users :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2005-05-30 00:53:26


Hi Elisha,

> I have a few questions about Boost.ProgramOptions pertaining to parsing
> an argv that is of wchar_t data type. The first thing that isn't clear
> from the examples is whether it's possible at all. The second thing
> that isn't clear is how to do it and store string values in std::wstring
> variables.
>
> Here are the specifics:
>
> 1) How do you use program_options with an argv argument that is a
> wchar_t data type?
>
> Like this?
>
> variables_map vm;
> store(parse_command_line<wchar_t>(argc, argv, desc), vm);

Exactly. You don't even need to specify 'wchar_t' explicitly.

> but then the question is how do you store any of the command line values
> in wstring variables?
>
> Like this?
>
> options_description desc("allowed options");
> desc.add_options()
> // First parameter describes option name/short name
> // The second is parameter to option
> // The third is description
> ("help,h", "print usage message")
> ("validate,v", value(&strFile), "validate xml file");

That's the supposed way. Here's a complete example taken from
"test/unicode_test.cpp"

    options_description desc;

    desc.add_options()
        ("foo", po::wvalue<wstring>(), "unicode option")
        ;

    vector<wstring> args;
    args.push_back(L"--foo=\x044F");

    variables_map vm;
    store(wcommand_line_parser(args).options(desc).run(), vm);

    BOOST_CHECK(vm["foo"].as<wstring>() == L"\x044F");

> // strFile is a wstring
>
> Well that doesn't work.

In what way and on what compiler and with what error messages, etc. I can't
help unless you tell exactly what's wrong.

> 2) I am getting 3 link errors when trying the above:
>
> ToolsTest.obj : error LNK2019: unresolved external symbol "void __cdecl
> boost::program_options::store(class
> boost::program_options::basic_parsed_options<unsigned short> const
> &,class boost::program_options::variables_map &)"
> (?store_at_program_options_at_boost@@YAXABV?$basic_parsed_options_at_G@12_at_AAVvari
> ables_map_at_12@@Z) referenced in function _main

Did you link to the program_options library, to begin with?

- Volodya


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