Opened 14 years ago

Closed 14 years ago

Last modified 8 years ago

#1904 closed Bugs (invalid)

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

Reported by: anonymous Owned by: Vladimir Prus
Milestone: To Be Determined Component: program_options
Version: Boost 1.35.0 Severity: Problem
Keywords: Cc:

Description

If one uses the boost_program_options, one gets a linker error: undefined reference to `boost::program_options::options_description::m_default_line_length'

Cause: boost/program_options/options_description.hpp, line 158

Currently:

static const unsigned m_default_line_length;

Should be:

static const unsigned m_default_line_length = 80;

The constant without assigneed value seems to become optimized out by the compiler.

Change History (8)

comment:1 by Vladimir Prus, 14 years ago

Resolution: invalid
Status: newclosed

The current behaviour is as designed -- options_description.hpp declares m_default_line_length. options_description.cpp has the definition. The error most likely means that you did not link your application to the program_options library.

comment:2 by (none), 14 years ago

Milestone: Boost 1.35.1

Milestone Boost 1.35.1 deleted

comment:3 by patbob@…, 14 years ago

I get this bug on Windows (VC++ 7.0 (2005)), boost 1.37.0. I am linking with program_options library. Perhaps this global is getting defined in some random boost library, but it certainly isn't in program_options lib where it belongs.

The value is declared, but not defined.. at least, not in the program_options library where it belongs.

If you get this error, provide an explicit line length to the options_description constructor so it doesn't try to use m_default_line_length. Like this:

po::options_description desc("Options", 1024);

I'm leaving this bug closed since it probably isn't a proiblem for most users... just windows users :)

comment:4 by patbob@…, 14 years ago

Problem "solved" -- for me, this issue was related to bug #2506 (program_options::arg undefined. Win DLL).

Need to define BOOST_PROGRAM_OPTIONS_DYN_LINK when using program options on windows in a DLL.

comment:5 by okobyzev@…, 11 years ago

Milestone: To Be Determined

it does not work on fresh GCC compilers also gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib64/gcc/x86_64-suse-linux/4.6/lto-wrapper Target: x86_64-suse-linux

so I think it need to be fixed

comment:6 by anonymous, 11 years ago

I can confirm this bug with the newest version of gcc (i.e. 4.6)

comment:7 by anonymous, 9 years ago

I got the same problem when I come to make gearmand1.1.11, I try to fix the /usr/local/boost/include/boost/program_options/options_description.hpp on line 175 static const unsigned m_default_line_length but it does not work for me , my god

comment:8 by Raffi Enficiaud, 8 years ago

I have the same problem. I use program_option through cmake, using the following define:

BOOST_ALL_NO_LIB

since I do not want autolink feature.

The two variables mentioned in this thread are not found at link time unless I define explicitely

BOOST_ALL_DYN_LINK

I do not have this problem with boost.system, boost.thread, boost.test and boost.chrono for instance. Looking at the config.h file, every define look fine (boost.program_options and boost.system). It looks like an incoherence in cmake find_boost module: the link is against the dynamic variants if Boost_USE_STATIC_LIBS is set to OFF, but the BOOST_ALL_DYN_LINK is not defined in Boost and should be defined manually.

Note: See TracTickets for help on using tickets.