https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78177
Bug ID: 78177
Summary: adding -flto flags causes linker error "undefined
reference to vtable"
Product: gcc
Version: 5.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: steve.lorimer at gmail dot com
Target Milestone: ---
I have code which compiles and links fine.
I'm now trying to enable link-time optimizations, but adding -flto to my
compiler and linker flags is causing a linker error:
/usr/local/lib/libboost_thread.a(thread.o): \
In function `void
boost::throw_exception<boost::bad_lexical_cast>(boost::bad_lexical_cast
const&)':
thread.cpp:(.text._ZN5boost15throw_exceptionINS_16bad_lexical_castEEEvRKT_[_ZN5boost15throw_exceptionINS_16bad_lexical_castEEEvRKT_]+0x124):
\
undefined reference to `vtable for boost::bad_lexical_cast'
The only flag I've added is -flto.
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto" )
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -flto" )
To be clear:
Without -flto the app builds and links fine
With -flto (and no other changes), the app fails to link with the above error
I'm running version 5.4.0-6ubuntu1~16.04.2