2012-05-04 8 views
4

Boost.Pool documentation氏は述べている(強調鉱山):- リンカエラー

#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; 
} 

私が得た:

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において、このようなコードをコンパイルしようとすると、リンカエラー:

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

Boost.Poolのドキュメントは間違っていますか? 私はここで何が欠けていますか? Boost.Poolはどのように使用できますか?

+1

'ブースト:: singleton_pool'は'ミューテックスを使用して'type:' boost :: thread'ライブラリにありますので、libboost _糸。 – nabulke

+0

あなたがboost \ pool \ detail \ mutex.hppを見ると、プールlibが独自のmutexを定義し、boost :: thread libを参照していないようです。 – Marius

+0

@MariusBucur:私の答えを確認するためにもう一度チェックします。 – nabulke

答えて

2

boost::threadにあるデフォルトのmutex実装は、ではなく、ヘッダーのみを使用しています。

は、依存関係を削除する方法については、以下に引用singleton_pool headerを参照してください:ブースト/設定/ user.hppで

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).

0

:261あなた #場合、私が思う

// 
// Turn threading support off if BOOST_DISABLE_THREADS is defined: 
// 
#if defined(BOOST_DISABLE_THREADS) && defined(BOOST_HAS_THREADS) 
# undef BOOST_HAS_THREADS 
#endif 

があります含める前にBOOST_DISABLE_THREADS を定義して解決します。 このオプションは、おそらくユーザーのためにビルドシステムに管理する必要があります。

+0

'#define BOOST_DISABLE_THREADS'が動作します。ありがとう。 –

0

私はブーストを見たものから、::スレッドLIBのプール依存性は(私はこれが不幸だと思う1.471.48

、それだけでlightweight mutexヘッダーを使用することであっただろう、より良い意思決定を参照してくださいブースト1_48に追加されました

あなたが他のlibsを使用している場合は特に、あなたはプールの\詳細\のmutex.hppを変更することができますが、おそらくスレッドのlibとリンクする簡単です。