Boost.Log with CMake causing undefined reference error

一个人想着一个人 提交于 2019-11-28 21:15:51

It looks like it boils down to linking to the shared version of Boost.Log.

There is a bit of detail on the issue in the docs for Boost.Log Your error message mentions the namespace boost::log::v2s_mt_posix and from the docs, this implies the linker is expecting to link to a static version of Boost.Log.

If you want to link to the shared version, it seems you need to define BOOST_LOG_DYN_LINK or BOOST_ALL_DYN_LINK, i.e. in your CMakeLists.txt add:

ADD_DEFINITIONS(-DBOOST_LOG_DYN_LINK)

If you want to link to the static version of Boost.Log, instead you need to add a CMake variable before calling FIND_PACKAGE(Boost ...):

SET(Boost_USE_STATIC_LIBS ON)
FIND_PACKAGE(Boost 1.54 COMPONENTS log REQUIRED)

For further variables which affect how CMake finds Boost, see the docs for FindBoost.

It is Boost_INCLUDE_DIRS not Boost_INCLUDE_DIR.

You could try enable Boost_USE_STATIC_LIBS

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