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

38,437

Solution 1

If you have installed boost from repo just use -lboost_program_options that will suffice.
If you installed boost libraries in some other library, you need to specify that directoty by -L/path/to/lib

In CMake you may specify set(CMAKE_CXX_FLAGS "-lboost_program_options")

However with CMake you should use

FIND_PACKAGE(Boost COMPONENTS program_options REQUIRED)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(target ${Boost_LIBRARIES})

Solution 2

There were changes to the <string> class in the C++11 standard which may conflict with versions of the Boost library that were compiled with a non-C++11 compiler (such as G++-4.8). Try recompiling boost or using a version of C++ compiler that was used to compile your Boost libraries.

Solution 3

Also double check that the setting of the pre-processor variable _GLIBCXX_USE_CXX11_ABI is identical to the setting of the variable that was used for compiling boost. The default setting of the variable may be different depending on the Linux distribution and version of the GNU compiler used.

See Dual ABI for more information.

Share:
38,437
Picowhat
Author by

Picowhat

Updated on January 05, 2020

Comments

  • Picowhat
    Picowhat over 4 years

    I am trying to compile a code and I get the error

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

    I use g++ in Ubuntu 12.04. Although I have done some C++ programming I am new to the Linux development environment (used only IDEs previously).

    So I did a basic search for this trouble, and found about some linking issues. I didn't quite understand them as I am a newbie. Reading some of those solutions confused me further. My boost library folder is in /usr/include. Some solutions says that it should be in /usr/lib. But I don't have any boost folder there.

    What do I need to change?