Boost.Log 与 CMake 导致未定义的参考错误
问题描述
我正在尝试在我正在处理的项目中使用新的 Boost.Log 库.该项目是使用 CMake 构建的.我收到链接错误,声称链接器遇到了对 Boost.Log 的未定义引用
I am trying to use the new Boost.Log library in a project I am working on. The project is built with CMake. I am receiving link errors claiming that the linker has come across undefined references to Boost.Log
我有一个简单的 hello world 测试,但由于这些错误而失败.如果我链接到 Boost.Log 库,什么会导致它生成未定义的引用错误?
I have a simple hello world test that fails with these errors. If I am linking against the Boost.Log libraries what would cause it to generate an undefined reference error?
main.cpp:
CMakeLists.txt:
CMakeLists.txt:
cmake 和 make 的详细输出
cmake:
制作:
推荐答案
看起来可以归结为链接到 Boost.Log 的共享版本.
It looks like it boils down to linking to the shared version of Boost.Log.
docs for Boost.Log 您的错误消息提到了命名空间 boost::log::v2s_mt_posix
并且从文档中,这意味着链接器期望链接到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.
如果你想链接到共享版本,似乎你需要定义BOOST_LOG_DYN_LINK
或BOOST_ALL_DYN_LINK
,即在你的CMakeLists.txt中添加:
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:
如果你想链接到 Boost.Log 的静态版本,你需要在调用 FIND_PACKAGE(Boost ...)
之前添加一个 CMake 变量之前:
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 ...)
:
有关影响 CMake 如何找到 Boost 的更多变量,请参阅 FindBoost
.
For further variables which affect how CMake finds Boost, see the docs for FindBoost
.
这篇关于Boost.Log 与 CMake 导致未定义的参考错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!