views:

143

answers:

2

I am trying to get a get the boost library program_options working on a simple windows console library. I have linked in the library C:\Program Files\boost\boost_1_40\lib\libboost_program_options-vc90-s-1_40.lib Included the header files

#include <boost/program_options.hpp>
#include <boost/program_options/config.hpp>
#include <boost/program_options/option.hpp>
#include <boost/program_options/detail/cmdline.hpp>
#include <boost/program_options/detail/parsers.hpp >

Defined _WIN32 (But I don't think it is required.)

And I still keep getting the

Error   1 error C3861: 'split_winmain': identifier not found

It should be so simple but I can't get it to work. Can anyone tell me what I need to do here. Joseph Shanahan

+1  A: 

That function is declared in the boost::program_options namespace. If all you do is use its name alone, the compiler doesn't know what you're talking about. You have a few options:

  • Use the fully qualified name when you call it:

    boost::program_options::split_winmain(...);
    
  • Tell the compiler which function you mean:

    using boost::program_options::split_winmain;
    split_winmain(...);
    
  • Bring the entire namespace into the current scope:

    using namespace boost::program_options;
    split_winmain(...);
    
  • Make a namespace alias:

    namespace po = boost::program_options;
    po::split_winmain(...);
    

I prefer the last one.

Do not define the _WIN32 macro; the compiler will do that for you when it's appropriate.

Rob Kennedy
There are some boost libaries which you need to build and including the header file in not sufficient program_options is one of these. You will get the information which you require at the following website.http://www.boost.org/doc/libs/1_40_0/more/getting_started/windows.html
Joseph Shanahan
I understand that. It's essentially what I told you in my response to your "follow-up answer." That's a linker issue. It's not relevant to compiler issue that this question and my answer are about.
Rob Kennedy
A: 

Thanks that answers that question. I should have got onto it myself. However now I have another related problem. It get program_options running do I need to link in 'libboost_program_options-vc90-mt-gd-1_40.lib I have got parts of the boost library working and I just included in the header file. Does program_options work differently. I keep getting a link error now. I am using VS2008

Error 1 fatal error LNK1104: cannot open file 'libboost_program_options-vc90-mt-gd-1_40.lib'

Joseph Shanahan
Welcome to Stack Overflow. Please do not use the "answer" section to post things that do not *answer* the current question. Use the "add comment" link instead. If an answer was helpful, vote it up. If it's the best answer, mark it with the checkmark. Your follow-up question is a different class of problem (linker vs. compiler), so it probably belongs in its own separate post. Most Boost things are header-only, but P.O. needs a compiled lib file; make sure the linker knows where to look. Set the "Additional Library Directories" project option or the /LIBPATH command-line option
Rob Kennedy