[Boost-users] program_options, parse_config_file problems

224 views
Skip to first unread message

Andrew E Slaughter

unread,
Apr 25, 2012, 8:48:58 PM4/25/12
to boost...@lists.boost.org
Hello,

I am attempting to parse configuration options from a file using
Boost::program_options. I am following the example provided on the
website
(http://www.boost.org/doc/libs/1_49_0/doc/html/program_options/overview.html#id2501135):

variables_map vm;
store(parse_command_line(argc, argv, desc), vm);
store(parse_config_file("example.cfg", desc), vm);
notify(vm);

I have included the following related to program_options:
#include <boost/program_options.hpp> // Boost Program Options
#include <boost/program_options/positional_options.hpp>
#include <boost/program_options/parsers.hpp>

I have the exact code as above in my program but receive the following
error. The program works fine if I comment out the line with the
parse_config_file line. Can someone please help me get this working.

Thanks,
Andrew

--- COMPILER ERROR --------------------------
/home/slaughter/Documents/programs/source/common/user_options/user_options.cpp:
In member function ‘void
SlaughterCommon::User_options::apply_options(int, char**)’:
/home/slaughter/Documents/programs/source/common/user_options/user_options.cpp:27:76:
error: no matching function for call to ‘parse_config_file(const char
[22], boost::program_options::options_description&, bool)’
/home/slaughter/Documents/programs/source/common/user_options/user_options.cpp:27:76:
note: candidates are:
/usr/include/boost/program_options/parsers.hpp:163:5: note:
template<class charT>
boost::program_options::basic_parsed_options<charT>
boost::program_options::parse_config_file(std::basic_istream<charT>&,
const boost::program_options::options_description&, bool)
/usr/include/boost/program_options/parsers.hpp:176:5: note:
template<class charT>
boost::program_options::basic_parsed_options<charT>
boost::program_options::parse_config_file(const char*, const
boost::program_options::options_description&, bool)
make[3]: ***
[source/common/CMakeFiles/common.dir/user_options/user_options.cpp.o]
Error 1
make[2]: *** [source/common/CMakeFiles/common.dir/all] Error 2
make[1]: *** [source/common/CMakeFiles/test_user_options.dir/rule] Error 2
make: *** [test_user_options] Error 2

_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Jeffrey Lee Hellrung, Jr.

unread,
Apr 25, 2012, 10:44:28 PM4/25/12
to boost...@lists.boost.org
On Wed, Apr 25, 2012 at 5:48 PM, Andrew E Slaughter <andrew.e....@gmail.com> wrote:
Hello,

I am attempting to parse configuration options from a file using Boost::program_options. I am following the example provided on the website (http://www.boost.org/doc/libs/1_49_0/doc/html/program_options/overview.html#id2501135):

variables_map vm;
store(parse_command_line(argc, argv, desc), vm);
store(parse_config_file("example.cfg", desc), vm);
notify(vm);

I have included the following related to program_options:
#include <boost/program_options.hpp> // Boost Program Options
#include <boost/program_options/positional_options.hpp>
#include <boost/program_options/parsers.hpp>

I have the exact code as above in my program but receive the following error. The program works fine if I comment out the line with the parse_config_file line. Can someone please help me get this working.

Thanks,
Andrew

--- COMPILER ERROR --------------------------
/home/slaughter/Documents/programs/source/common/user_options/user_options.cpp: In member function ‘void SlaughterCommon::User_options::apply_options(int, char**)’:
/home/slaughter/Documents/programs/source/common/user_options/user_options.cpp:27:76: error: no matching function for call to ‘parse_config_file(const char [22], boost::program_options::options_description&, bool)’
/home/slaughter/Documents/programs/source/common/user_options/user_options.cpp:27:76: note: candidates are:
/usr/include/boost/program_options/parsers.hpp:163:5: note: template<class charT> boost::program_options::basic_parsed_options<charT> boost::program_options::parse_config_file(std::basic_istream<charT>&, const boost::program_options::options_description&, bool)
/usr/include/boost/program_options/parsers.hpp:176:5: note: template<class charT> boost::program_options::basic_parsed_options<charT> boost::program_options::parse_config_file(const char*, const boost::program_options::options_description&, bool)
[...snip...]

So this overload looks like the one you want, but it has a non-deduced template parameter charT (which should probably be deduced to be char? I'm not sure). I got the short program below to compile by explicitly specifying the charT template parameter as char.

#include <boost/program_options.hpp>

int main(int argc, char* argv[])
{
    using namespace boost::program_options;
    options_description desc;

    variables_map vm;
    store(parse_command_line(argc, argv, desc), vm);
    store(parse_config_file< char >("example.cfg", desc), vm);
    notify(vm);
    return 0;
}

Please file a trac ticket alerting the Boost.ProgramOptions maintainer of the compiler failure of the example snippet in the docs.

HTH,

- Jeff

Reply all
Reply to author
Forward
0 new messages