私は現在、CMNとGTという2つのDLLライブラリを持っています。 GTはCMNに依存しています。Visual Studio 2003から2010への開発環境の移植:なぜLNK2005エラーが発生するのですか?
Visual Studio 2003では、問題なく両方のライブラリをコンパイルしてリンクすることができます。私はVisual Studio 2010でCMNとGTを正常にコンパイルし、CMNをリンクすることができます。しかし、GTをリンクしようとすると、次のエラーが発生します。
CMN.lib(CMN.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> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" ([email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@Z) already defined in TokenizerAdvanced.obj
CMN.lib(CMN.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)" ([email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]) already defined in TokenizerAdvanced.obj
CMN.lib(CMN.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> >(char const *)" ([email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@Z) already defined in TokenizerAdvanced.obj
CMN.lib(CMN.dll) : error LNK2005: "public: void __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::reserve(unsigned int)" ([email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]) already defined in TokenizerAdvanced.obj
CMN.lib(CMN.dll) : error LNK2005: "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > & __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::erase(unsigned int,unsigned int)" ([email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@Z) already defined in TokenizerAdvanced.obj
TokenizerAdvancedはGTのソースファイルです。
すべてのコンパイルとリンクは、同じコマンドライン構造(-MDdを使用してコンパイル)で行われます。この問題の原因となるVisual Studio 2003と2010の間で何が変更されましたか?
編集:不思議なことに、私はビルドからTokenizerAdvanced.cppを除外した場合(他のファイルは - Tokenizer.cppがそれを参照しない)、私は未解決の外部エラーを取得:
Tokenizer.obj : error LNK2001: unresolved external symbol "public: static unsigned int const std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::npos" ([email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@2IB)
編集を:調査を回答に移しました。
同じランタイムライブラリを使用していますか? http://en.wikipedia.org/wiki/Visual_C%2B%2B#Issues – INS
はい。私は両方のコマンドラインを(本質的に)同じように使ってきました。ビルド時に環境が唯一の大きな違いになるはずです。 – tvStatic
'TokenizerAdvanced'ファイルを参照してください。それを(完全にまたは部分的に)コメントアウトし、何が起こるか見てみてください。あなたのDLLでいくつかの静的ランタイムライブラリを使用していますか? – INS