我有编译和链接的代码。
我现在正在尝试启用链接时优化,但是将-flto
添加到我的编译器和链接器标志会导致链接器错误:
/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'
我添加的唯一标志是-flto
。
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto" )
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -flto" )
要明确:
-flto
应用构建和链接正常-flto
(并且没有其他更改),该应用无法与上述错误链接导致此链接器错误的原因是什么?