问题
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
What is causing this linker error?
来源:https://stackoverflow.com/questions/40350936/enabling-link-time-optimizations-causes-a-linker-error