c++ - 在 VS2010 中使用 Boost.Pool - 链接器错误

标签 c++ boost

Boost.Pool documentation说(强调我的):

The Boost Pool library is a header-only library. That means there is no .lib, .dll, or .so to build; just add the Boost directory to your compiler's include file path, and you should be good to go!

但是当我尝试在 VS2010 SP1 中编译这样的代码时:

#include <string>
#include <vector>

#include <boost\pool\pool_alloc.hpp>

int main()
{
    typedef std::basic_string<wchar_t, std::char_traits<wchar_t>, 
        boost::pool_allocator<wchar_t>> PoolString;

    std::vector<PoolString> vec;
    for (int i = 0; i < 100; i++)
    {
        PoolString s(L"Some test string. ABCDEF.");
        vec.push_back(s);
    }

    // Release pool memory
    boost::singleton_pool<boost::pool_allocator_tag, sizeof(wchar_t)>::release_memory();

    return 0;
}

我遇到链接器错误:

error LNK1104: cannot open file 'libboost_thread-vc100-mt-gd-1_49.lib'

Boost.Pool 文档是否不正确? 我在这里错过了什么? 如何使用 Boost.Pool?

最佳答案

boost::singleton_pool 使用位于 boost::thread 中的默认互斥锁实现,不是 仅 header 。

参见 singleton_pool header下面引用有关如何删除依赖项的信息:​​

Mutex This class is the type of mutex to use to protect simultaneous access to the underlying Pool. Can be any Boost.Thread Mutex type or boost::details::pool::null_mutex. It is exposed so that users may declare some singleton pools normally (i.e., with synchronization), but some singleton pools without synchronization (by specifying boost::details::pool::null_mutex) for efficiency reasons. The member typedef mutex exposes the value of this template parameter. The default for this parameter is boost::details::pool::default_mutex which is a synonym for either boost::details::pool::null_mutex (when threading support is turned off in the compiler (so BOOST_HAS_THREADS is not set), or threading support has ben explicitly disabled with BOOST_DISABLE_THREADS (Boost-wide disabling of threads) or BOOST_POOL_NO_MT (this library only)) or for boost::mutex (when threading support is enabled in the compiler).

关于c++ - 在 VS2010 中使用 Boost.Pool - 链接器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10447424/

相关文章:

虚幻引擎 4 中的 C++ 嵌套 JSON

c++ - 在 C/C++ 中检查 NULL 指针

C++ 在多态对象中引用

c++ - boost::associative_property_map() 编译错误

c++ - PCL安装链接直接以某种方式 boost 安装目录

c++ - Winapi 设置事件选项卡控件

c++ - 错误 : expected ')' before '&' token

c++ - boost 单元测试夹具继承测试类,可以访问 protected 方法?

c++ - 可以将多个 boost::signal 连接到 1 个插槽吗?

c++ - 迁移工作模块时 Boost "is_virtual_base_of"编译错误