On Wed, Apr 25, 2012 at 5:48 PM, Andrew E Slaughter <andrew.e.slaughter@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