Questions about Boost.ProgramOptions

Hi, 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); 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"); // strFile is a wstring Well that doesn't work. 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@program_options@boost@@YAXABV?$basic_parsed_options@G@12@AAVvari ables_map@12@@Z) referenced in function _main ToolsTest.obj : error LNK2019: unresolved external symbol "public: __thiscall boost::program_options::basic_parsed_options<unsigned short>::basic_parsed_options<unsigned short>(class boost::program_options::basic_parsed_options<char> const &)" (??0?$basic_parsed_options@G@program_options@boost@@QAE@ABV?$basic_parse d_options@D@12@@Z) referenced in function "public: class boost::program_options::basic_parsed_options<unsigned short> __thiscall boost::program_options::basic_command_line_parser<unsigned short>::run(void)const " (?run@?$basic_command_line_parser@G@program_options@boost@@QBE?AV?$basic _parsed_options@G@23@XZ) ToolsTest.obj : error LNK2019: unresolved external symbol "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl boost::program_options::to_internal(class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> > const &)" (?to_internal@program_options@boost@@YA?AV?$basic_string@DU?$char_traits @D@std@@V?$allocator@D@2@@std@@ABV?$basic_string@GU?$char_traits@G@std@@ V?$allocator@G@2@@4@@Z) referenced in function "class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > __cdecl boost::program_options::to_internal<class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> > >(class std::vector<class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> >,class std::allocator<class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> > > > const &)" (??$to_internal@V?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@ @std@@@program_options@boost@@YA?AV?$vector@V?$basic_string@DU?$char_tra its@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_ traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@ABV?$vector@V?$basic_strin g@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@V?$allocator@V?$basic_st ring@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@@2@@3@@Z) Thanks for any help here, Elisha Berns e.berns@computer.org tel. (310) 556 - 8332 fax (310) 556 - 2839

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@program_options@boost@@YAXABV?$basic_parsed_options@G@12@AAVvari ables_map@12@@Z) referenced in function _main
Did you link to the program_options library, to begin with? - Volodya

-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users- bounces@lists.boost.org] On Behalf Of Vladimir Prus Sent: Sunday, May 29, 2005 10:53 PM To: boost-users@lists.boost.org Subject: [Boost-users] Re: Questions about Boost.ProgramOptions
Hi Elisha,
I have a few questions about Boost.ProgramOptions pertaining to
Thanks for the reply, The compiler is VC7.1 and I rely on the compiler to automatically find the correct library. If that is incorrect, which version should I link to? The suffixes are a bit opaque with all of the s, g and m characters. But before that I made changes as per the example of unicode_test.cpp and it still doesn't compile. Here's my code: wstring strXmlFile; wstring strXsdFile; // process program options 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", "validate xml file") ("xml", wvalue<wstring>(&strXmlFile), "xml file") ("xsd", wvalue<wstring>(&strXsdFile), "xsd file"); variables_map vm; store(wcommand_line_parser(argc, argv).options(desc).run(), vm); Here's the errors: c:\Libraries\Boost\boost_1_32_0\boost\lexical_cast.hpp(144) : error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'const std::basic_string<_Elem,_Traits,_Ax>' (or there is no acceptable conversion) with [ _Elem=wchar_t, _Traits=std::char_traits<wchar_t>, _Ax=std::allocator<wchar_t> ] c:\Libraries\Boost\boost_1_32_0\boost\lexical_cast.hpp(143) : while compiling class-template member function 'bool boost::detail::lexical_stream<Target,Source>::operator <<(const Source &)' with [ Target=std::wstring, Source=std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocato r<wchar_t>> ] c:\Libraries\Boost\boost_1_32_0\boost\lexical_cast.hpp(186) : see reference to class template instantiation 'boost::detail::lexical_stream<Target,Source>' being compiled with [ Target=std::wstring, Source=std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocato r<wchar_t>> ] c:\Libraries\Boost\boost_1_32_0\boost\program_options\detail\value_seman tic.hpp(81) : see reference to function template instantiation 'Target boost::lexical_cast<T,std::basic_string<_Elem,_Traits,_Ax>>(Source)' being compiled with [ Target=std::wstring, T=std::wstring, _Elem=wchar_t, _Traits=std::char_traits<wchar_t>, _Ax=std::allocator<wchar_t>, Source=std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocato r<wchar_t>> ] c:\Libraries\Boost\boost_1_32_0\boost\program_options\detail\value_seman tic.hpp(149) : see reference to function template instantiation 'void boost::program_options::validate<T,wchar_t>(boost::any &,const std::vector<_Ty> &,T *,long)' being compiled with [ T=std::wstring, _Ty=std::wstring ] c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\map(36) : while compiling class-template member function 'void boost::program_options::typed_value<T,charT>::xparse(boost::any &,const std::vector<_Ty> &) const' with [ T=std::wstring, charT=wchar_t, _Ty=std::wstring ] c:\Samples\XMLComponents\Composite\XmlTools\XmlToolsTest.cpp(46) : see reference to class template instantiation 'boost::program_options::typed_value<T,charT>' being compiled with [ T=std::wstring, charT=wchar_t ] c:\Libraries\Boost\boost_1_32_0\boost\lexical_cast.hpp(144) : error C2228: left of '.fail' must have class/struct/union type Thanks for any help here, Elisha 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@program_options@boost@@YAXABV?$basic_parsed_options@G@12@AAVvari
ables_map@12@@Z) referenced in function _main
Did you link to the program_options library, to begin with?
- Volodya
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Elisha Berns wrote:
// process program options 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", "validate xml file") ("xml", wvalue<wstring>(&strXmlFile), "xml file") ("xsd", wvalue<wstring>(&strXsdFile), "xsd file");
variables_map vm; store(wcommand_line_parser(argc, argv).options(desc).run(), vm);
Here's the errors:
c:\Libraries\Boost\boost_1_32_0\boost\lexical_cast.hpp(144) : error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'const std::basic_string<_Elem,_Traits,_Ax>' (or there is no
I believe this error happens with wchar_t is not considered as native type by the VC7.* compiler. Try passing the /Zc:wchar_t option. - Volodya
participants (2)
-
Elisha Berns
-
Vladimir Prus