Enabling link-time optimizations causes a linker error?

不打扰是莪最后的温柔 提交于 2020-03-19 02:41:05

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!