Opened 10 years ago

Last modified 10 years ago

#6903 new Bugs

Including program options header breaks using g++ -static -flto -std=c++11

Reported by: boostBugs@… Owned by: Vladimir Prus
Milestone: To Be Determined Component: program_options
Version: Boost 1.49.0 Severity: Problem
Keywords: g++ lto Cc:

Description

A minimal example is simply

#include "boost/program_options.hpp"

int main ( int argC, char* argV[] )
{
    return 0;
}

Compiling this using either
g++ main.cpp -static -flto -std=c++11 -fwhole-program
or
g++ main.cpp -static -flto -std=c++11 -fno-use-linker-plugin
gives a lot of errors:

`_ZTIN9gnu_cxx24concurrence_lock_errorE' referenced in section `.text._ZN9gnu_cxx30throw_concurrence_lock_errorEv[_ZN9gnu_cxx30throw_concurrence_lock_errorEv]' of /usr/lib/gcc/x86_64-linux-gnu/4.7/libstdc++.a(eh_alloc.o): defined in discarded section `.gnu.linkonce.t._ZTIN9gnu_cxx24concurrence_lock_errorE' of /tmp/ccEoPVoT.o (symbol from plugin)
...
collect2: error: ld returned 1 exit status

I tried g++4.6 and 4.7. I am not sure if it is a bug within the g++ or within boost. If either -static, -flto or -std=c++11 is omited the program compiles fine. Only if all three are present the error occours. I am using Debian Wheezy.

Change History (4)

comment:1 by anonymous, 10 years ago

I have a similar problem linking statically with -flto and -std=gnu++0x

typeinfo for boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::bad_weak_ptr> >' referenced in section .text._ZNK5boost16exception_detail10clone_implINS0_19error_info_injectorINS_12bad_weak_ptrEEEE7rethrowEv[boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::bad_weak_ptr> >::rethrow() const]' of /home/bsun/phoenix/opt/cpplibraries/boost/1_49_0/lib/gcc-4.6/libboost_thread-mt-s.a(thread.o): defined in discarded section `.gnu.linkonce.t._ZTIN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_12bad_weak_ptrEEEEE' of ./src/test/router.o (symbol from plugin)

comment:2 by anonymous, 10 years ago

I have the same problem: g++-4.7 only, but event without -flto this error appears...

comment:3 by anonymous, 10 years ago

Which binutils version did you use? Which flags did you set to compile boost. IMO -flto must be passed when compiling boost libs if I correctly understand the docs:

gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html

comment:4 by anonymous, 10 years ago

created a gcc 4.7.1 build on debian squeeze using crosstool-ng and mostly latest versions of all required libs resulted in no errors. A small Note: I compiled boost, icu, zlib, bzlib with -flto flag as well.

Note: See TracTickets for help on using tickets.