c++ - boost 池: can I wean it from boost system?

标签 c++ boost

1.53.0 中 pool 的文档声称它是“仅 header ”。然而,一个最小的程序:

#include <boost/pool/pool_alloc.hpp>

int main() {
  return 0;
}

最终得到来自 boost_system 的 undefined symbol ,并且 bcp 认为 boost_system 是必需的。有#define或其他方法可以解决这个问题吗?

最佳答案

这是一个已知错误。 https://svn.boost.org/trac/boost/ticket/7085

  • 如果您不需要多线程,我们可以 修改pool/detail/mutex.hpp 包括 <boost/thread/mutex.hpp>如 URL 中所述,

    ...
    #if defined(BOOST_HAS_THREADS) && !defined(BOOST_NO_MT) && !defined(BOOST_POOL_NO_MT) 
    #include <boost/thread/mutex.hpp>
    #endif
    ...
    
  • 或者,如果您无法修改文件,请伪造编译器 <boost/thread/mutex.hpp>已定义:

    #define BOOST_POOL_NO_MT       // disable multi-threading
    #define BOOST_THREAD_MUTEX_HPP // define the #include-guard to disable the header
    
    #include <boost/pool/pool_alloc.hpp>
    
    int main () {}
    
  • 或者,如果您确实需要多线程,但 C++11 是允许的,我们可以使用 std::mutex替代boost::mutex :

    #define BOOST_THREAD_MUTEX_HPP
    #include <mutex>
    namespace boost {
        using std::mutex;
    }
    
    #include <boost/pool/pool_alloc.hpp>
    
    int main () {}
    

关于c++ - boost 池: can I wean it from boost system?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17000542/

相关文章:

c++ - 使用 boost::phoenix::bind 和 boost::spirit::qi::symbols::add

boost - 如何在不影响插入顺序的情况下替换多索引容器中的项目?

c++ - 使用 Boost::Spirit 解析异构数据

html - 如何使用 Boost ptree C++ 解析其值中包含 HTML 标记的 XML

c++ - 是否可以将 bitset<8> 转换为整数字符数组?

c++ - 交叉编译库通信

c++ - 为什么 C++ 中的 ClassName ClassName 变量定义可以正常编译和工作?

c++ - Visual Studio 11 中生成命令和属性的宏

c++ - 哪些标准的 C++ 类不能在 C++ 中重新实现?

具有可移动节点、可访问属性和可靠 ID 的 C++ 图形