Boost Program Options won't work with GLIBCXX_DEBUG
Asked Answered
E

1

12

I have the following sample code:

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

int main ( int ac, char *av[] ) {
    // Declare the supported options.
    boost::program_options::options_description desc("Allowed options");
    desc.add_options()("help", "produce help message");

    boost::program_options::variables_map vm;
    boost::program_options::store(boost::program_options::parse_command_line(ac, av, desc), vm);
    return 0;
}

It compiles fine using e.g. g++ test.cpp -lboost_program_options. However if I try to activate GCC bounds checking with the call g++ test.cpp -lboost_program_options -D_GLIBCXX_DEBUG, it throws the following linker error:

/tmp/ccZLdZ1g.o: In function `boost::program_options::basic_command_line_parser<char>::basic_command_line_parser(int, char const* const*)':
test.cpp:(.text._ZN5boost15program_options25basic_command_line_parserIcEC2EiPKPKc[_ZN5boost15program_options25basic_command_line_parserIcEC5EiPKPKc]+0x97): undefined reference to `boost::program_options::detail::cmdline::cmdline(std::__debug::vector<std::string, std::allocator<std::string> > const&)'
collect2: error: ld returned 1 exit status

As far as I understand the linker can't find the function boost::program_options::detail::cmdline::cmdline(std::__debug::vector<std::string, std::allocator<std::string> > const&), because its argument is replaced by a debug vector instead of normal std::vector. But why does this happen? And does anyone know a workaround, to make Boost Program Options work with GLIBCXX_DEBUG?

I use the following system:

  • Debian Wheezy
  • g++ (Debian 4.7.2-5) 4.7.2
  • libboost-all-dev 1.49.0.1, installed via aptitude

Thanks for any help

Ecchymosis answered 1/11, 2013 at 14:43 Comment(3)
Looks like you need a debug libraries for boost::program_optionsDike
@P0W, I assume that these are the boost libraries compiled with GLIBCXX_DEBUG, right? So is there a convenient way to get those and to switch between the two?Ecchymosis
No, the -dev suffix generally means the package includes developer headers and libraries to link against. It does not imply libstdc++ iterator debugging is enabled.Beasley
B
7

The error message is very clear here, the linker cannot find the symbol

boost::program_options::detail::cmdline::cmdline(std::__debug::vector<std::string, std::allocator<std::string> > const&)

note the additional __debug namespace, which implies you are building with _GLIBCXX_DEBUG. This won't work since your package maintainer did not build the boost libraries with this defined, hence the linker error. You have a few options

  • remove _GLIBCXX_DEBUG from whatever translation units include the program options headers. This might require some refactoring depending on what you're trying to solve with iterator debugging enabled.
  • build the boost libraries with -D_GLIBCCX_DEBUG. This also may not be trivial, though the boost build system is fairly straightforward.
Beasley answered 1/11, 2013 at 16:47 Comment(3)
Ok thanks. I succeeded in building the required boost libraries from source with -D_GLIBCCX_DEBUG and it works. However I find it somehow disappointing that the default boost installation does not work with bounds checking enabled. The corresponding debug symbols could just be included in the library, couldn't they?Ecchymosis
@Ecchymosis there is no default boost installation, your package maintainer might offer several choices. Though I doubt any will have iterator debugging enabled. It is more than just debug symbols, the libraries have to be recompiled with the _GLIBCXX_DEBUG flag defined.Beasley
@Ecchymosis how did you compile boost wiht -D_GLIBCXX_DEBUG?Legalize

© 2022 - 2024 — McMap. All rights reserved.