c++ - 添加 boost 日志依赖项时出现 undefined reference 错误

标签 c++ boost

我正在尝试添加 boost 日志记录功能。

但是我在 undefined reference 上有很多错误。

D:\c++\boost_1_58_0\bin.v2\libs\log\build\gcc-mingw-5.1.0\debug\link-static\threading-multi/libboost_log-mgw51-mt-d-1_58.a(core.o): In function `boost::thread_specific_ptr<boost::log::v2s_mt_nt5::core::implementation::thread_data>::~thread_specific_ptr()':
D:\c++\boost_1_58_0/./boost/thread/tss.hpp:79: undefined reference to `boost::detail::set_tss_data(void const*, boost::shared_ptr<boost::detail::tss_cleanup_function>, void*, bool)'
D:\c++\boost_1_58_0\bin.v2\libs\log\build\gcc-mingw-5.1.0\debug\link-static\threading-multi/libboost_log-mgw51-mt-d-1_58.a(core.o): In function `boost::thread_specific_ptr<boost::log::v2s_mt_nt5::core::implementation::thread_data>::get() const':
D:\c++\boost_1_58_0/./boost/thread/tss.hpp:84: undefined reference to `boost::detail::get_tss_data(void const*)'
D:\c++\boost_1_58_0\bin.v2\libs\log\build\gcc-mingw-5.1.0\debug\link-static\threading-multi/libboost_log-mgw51-mt-d-1_58.a(core.o): In function `boost::thread_specific_ptr<boost::log::v2s_mt_nt5::core::implementation::thread_data>::reset(boost::log::v2s_mt_nt5::core::implementation::thread_data*)':
D:\c++\boost_1_58_0/./boost/thread/tss.hpp:105: undefined reference to `boost::detail::set_tss_data(void const*, boost::shared_ptr<boost::detail::tss_cleanup_function>, void*, bool)'
D:\c++\boost_1_58_0\bin.v2\libs\log\build\gcc-mingw-5.1.0\debug\link-static\threading-multi/libboost_log-mgw51-mt-d-1_58.a(record_ostream.o): In function `get':
D:\c++\boost_1_58_0/./boost/thread/tss.hpp:84: undefined reference to `boost::detail::get_tss_data(void const*)'
D:\c++\boost_1_58_0\bin.v2\libs\log\build\gcc-mingw-5.1.0\debug\link-static\threading-multi/libboost_log-mgw51-mt-d-1_58.a(record_ostream.o): In function `reset':
D:\c++\boost_1_58_0/./boost/thread/tss.hpp:105: undefined reference to `boost::detail::set_tss_data(void const*, boost::shared_ptr<boost::detail::tss_cleanup_function>, void*, bool)'
D:\c++\boost_1_58_0\bin.v2\libs\log\build\gcc-mingw-5.1.0\debug\link-static\threading-multi/libboost_log-mgw51-mt-d-1_58.a(record_ostream.o): In function `get':
D:\c++\boost_1_58_0/./boost/thread/tss.hpp:84: undefined reference to `boost::detail::get_tss_data(void const*)'
D:\c++\boost_1_58_0\bin.v2\libs\log\build\gcc-mingw-5.1.0\debug\link-static\threading-multi/libboost_log-mgw51-mt-d-1_58.a(record_ostream.o): In function `reset':
D:\c++\boost_1_58_0/./boost/thread/tss.hpp:105: undefined reference to `boost::detail::set_tss_data(void const*, boost::shared_ptr<boost::detail::tss_cleanup_function>, void*, bool)'
D:\c++\boost_1_58_0\bin.v2\libs\log\build\gcc-mingw-5.1.0\debug\link-static\threading-multi/libboost_log-mgw51-mt-d-1_58.a(record_ostream.o): In function `~thread_specific_ptr':
D:\c++\boost_1_58_0/./boost/thread/tss.hpp:79: undefined reference to `boost::detail::set_tss_data(void const*, boost::shared_ptr<boost::detail::tss_cleanup_function>, void*, bool)'
D:\c++\boost_1_58_0/./boost/thread/tss.hpp:79: undefined reference to `boost::detail::set_tss_data(void const*, boost::shared_ptr<boost::detail::tss_cleanup_function>, void*, bool)'
D:\c++\boost_1_58_0\bin.v2\libs\log\build\gcc-mingw-5.1.0\debug\link-static\threading-multi/libboost_log-mgw51-mt-d-1_58.a(severity_level.o): In function `void boost::this_thread::at_thread_exit<boost::_bi::bind_t<boost::_bi::unspecified, boost::checked_deleter<unsigned long long>, boost::_bi::list1<boost::_bi::value<unsigned long long*> > > >(boost::_bi::bind_t<boost::_bi::unspecified, boost::checked_deleter<unsigned long long>, boost::_bi::list1<boost::_bi::value<unsigned long long*> > >)':
D:\c++\boost_1_58_0/./boost/thread/detail/thread.hpp:861: undefined reference to `boost::detail::add_thread_exit_function(boost::detail::thread_exit_function_base*)'
D:\c++\boost_1_58_0\bin.v2\libs\log\build\gcc-mingw-5.1.0\debug\link-static\threading-multi/libboost_log-mgw51-mt-d-1_58.a(once_block.o): In function `boost::detail::basic_cv_list_entry::wait(boost::detail::timeout)':
D:\c++\boost_1_58_0/./boost/thread/win32/condition_variable.hpp:94: undefined reference to `boost::this_thread::interruptible_wait(void*, boost::detail::timeout)'
D:\c++\boost_1_58_0\bin.v2\libs\log\build\gcc-mingw-5.1.0\debug\link-static\threading-multi/libboost_log-mgw51-mt-d-1_58.a(thread_id.o): In function `at_thread_exit<boost::log::v2s_mt_nt5::aux::this_thread::(anonymous namespace)::id_storage::deleter>':
D:\c++\boost_1_58_0/./boost/thread/detail/thread.hpp:861: undefined reference to `boost::detail::add_thread_exit_function(boost::detail::thread_exit_function_base*)'
collect2.exe: error: ld returned 1 exit status

我的链接库看起来像这样。

enter image description here

我的 include 声明如下所示

enter image description here

我的 boost include 文件夹也位于主 x86_64-w64-mingw32 包含文件夹中

最佳答案

在 Windows 10、Cygwin GCC 设置下有同样的错误。除了 boost_log 和 boost_log_setup 之外,我还必须单独链接 boost_thread。

-lboost_log_setup -lboost_log -lboost_thread
我使用的是 BOOST 1.66。

关于c++ - 添加 boost 日志依赖项时出现 undefined reference 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31780828/

相关文章:

部分数据的 C++ 正则表达式

c++ - BOOST_PHOENIX_ADAPT_FUNCTION(...) 在模板化容器上使用模板化函数

c++ - boost 线程 : threads or processes?

c++ - 为什么我从 GNU g++ 和 VC++ 得到不同的结果

c++ - 计算负实数值的 Gamma 函数(C++、Boost)

c++ - 当在头文件而不是 CPP 文件上实现时,析构函数会导致内存泄漏 - 仅在 linux 上

c++ - 如何在 C++ 中手动抛出 "overflow exception"?

c++ - Boost::公历和闰年

c++ - 将指针分配给两个指针的按位或

c++ - C/C++ 中奇异复方矩阵的伪逆 (SVD)