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中,不仅仅是头文件.
有关如何删除依赖项的信息,请参阅下面引用的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).