vendredi 21 juillet 2017

Boost lib giving error : undefined reference to boost::program_options::options_description::m_default_line_length' on win7 in codeblocks

I'm trying to use Boost C++ library for a simple CLI cmd parsing option but i am facing many Error's saying:

undefined reference to boost::program_options::options_description::m_default_line_length

I'm on Windows 7 for codeblocks IDE 16.01 and I am using GCC Toolchain from MinGW. I Downloaded Boost library 1.63.0 from - http://ift.tt/2uOWbFK

I build the boost library using following cmd as mention on boost.org

    > bootstrap.bat gcc
    > b2 toolset=gcc -std=c++11 (Since i want C++11 standard )

to link / use the boost library with codeblocks i did following steps

in the project -> build option -> searchdirectories -> compiler i added : C: ....\boost_1_63_0 (i added commplete path here)

in the project -> build option -> searchdirectories -> linker i added : C: ....\boost_1_63_0\stage\lib (i added commplete path)

in the project -> build option -> linkersetting -> add i added : libboost_system-mgw71-mt-d-1_63.a (i added commplete path) and i added : libboost_program_options-mgw71-mt-d-1_63.a and i added : libboost_filesystem-mgw71-mt-d-1_63.a

Now in the project -> build option -> compilersetting -> compilerflag I selected: follow c++11 std (-std=c++1) flag.

and i am using following code given on boost website.

#include <boost/program_options.hpp>
#include <iostream>

using namespace boost::program_options;

void on_age(int age)
{
  std::cout << "On age: " << age << '\n';
}

int main(int argc, const char *argv[])
{
  try
  {
    options_description desc{"Options"};
    desc.add_options()
    ("help,h", "Help screen")
    ("pi", value<float>()->default_value(3.14f), "Pi")
    ("age", value<int>()->notifier(on_age), "Age");

      ..... // some more code is here.. 
  }
  catch (const error &ex)
  {
    std::cerr << ex.what() << '\n';
  }   }

But I keep getting error: -

undefined reference to boost::program_options::options_description::m_default_line_length

undefined reference to boost::program_options::options_description::m_default_line_length

undefined reference to boost::program_options::options_description::options_description( std::string const&, unsigned int, unsigned int)

undefined reference to boost::program_options::options_description::add_options()

I even tried to add compiler flag in other compiler option ->

-lboost_program_options

But then also I am getting these error. And if I don't select -std=c++11 option in compiler setting then i get the following error -

in C++98 'desc' must be initialized by constructor, not by '{...}'

Can anyone help me to solve these issue?

Why these issues are coming ?? any solutions ??

I am planning to use Boots Library for CLI parsing Python and C++ communication and serialization. but I got stuck in very basic itself.

NOTE: I am using codeblock 16.01, Boost library 01.63.01 and MinGW gcc toolchain.

Any Help or suggestions will be highly appreciated. *

Thanks, Maneesh

Aucun commentaire:

Enregistrer un commentaire