現在、boost lib にリンクしようとしています。
libboost_regex-vc90-mt-gd-1_53.lib
このコマンドラインから作成されます
b2^
--stagedir=%BOOST_OUTPUT_DIR%^
--build-dir=%BOOST_BUILD_DIR%^
toolset=msvc-9.0^
link=static^
variant=release,debug^
threading=multi^
runtime-link=shared^
stage
しかし、次のリンケージエラーが発生します(他の多くのエラーの1つ):
msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)" (??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) déjà défini(e) dans TrailerContest.Reflection.obj
このエラーについて詳しく知るために、リンカの詳細度を上げました。これが得られる結果です。
Searching c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\lib\msvcprtd.lib :
1> "__declspec(dllimport) public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)" (__imp_??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) found
1> Referenced in libboost_date_time-vc90-mt-gd-1_53.lib(greg_month.obj)
1> Referenced in libboost_random-vc90-mt-gd-1_53.lib(random_device.obj)
1> Referenced in libboost_thread-vc90-mt-gd-1_53.lib(thread.obj)
1> Referenced in libboost_regex-vc90-mt-gd-1_53.lib(instances.obj)
1> Referenced in libboost_regex-vc90-mt-gd-1_53.lib(regex.obj)
1> Referenced in libboost_regex-vc90-mt-gd-1_53.lib(w32_regex_traits.obj)
1> Referenced in libboost_system-vc90-mt-gd-1_53.lib(error_code.obj)
1> Loaded msvcprtd.lib(MSVCP90D.dll)
1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)" (??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) already defined in TrailerContest.Reflection.obj
すべてのブースト ライブラリが、MSVCP90D.dll から std::string 関数をインポートしようとしているようです。
__imp_??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ
私自身のプログラムは std::string コードを埋め込んでいるように見えるため、内部的にリンクしようとします。
??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ
ここでは 2 つの選択肢があると思います。ブーストを埋め込み std::string コードにするか、ブーストと私のプログラムが両方の obj で同じ宣言を持ち、リンケージを達成できるようにします。私のプログラムは、ブーストと同じ方法で MSVCP90D.dll から std::string コードをインポートする必要があります。
問題は、std::string コードをインポートせずにブーストにコンパイルを依頼する方法がわからないことです。そして、プログラムに MSVCP90D.dll から std::string を強制的にインポートする方法がわかりません。誰かアイデアがありますか?
私のプログラムは明らかに /MDd オプションでコンパイルされていると言わざるを得ません。Boost は、このオプションを使用して、 runtime-link=shared行でコンパイルする必要もあります。