0

私は現在、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) 

編集を:調査を回答に移しました。

+0

同じランタイムライブラリを使用していますか? http://en.wikipedia.org/wiki/Visual_C%2B%2B#Issues – INS

+0

はい。私は両方のコマンドラインを(本質的に)同じように使ってきました。ビルド時に環境が唯一の大きな違いになるはずです。 – tvStatic

+1

'TokenizerAdvanced'ファイルを参照してください。それを(完全にまたは部分的に)コメントアウトし、何が起こるか見てみてください。あなたのDLLでいくつかの静的ランタイムライブラリを使用していますか? – INS

答えて

0

私はこの問題を発見したと思います。私たちはCMNの文字列から派生するクラスを持っています。 hereを参照してください。

This discussionは、クライアントライブラリのソースコードに以下を追加示唆:

template std::string::size_type std::string::npos; 
template std::wstring::size_type std::wstring::npos; 

しかし、これは私のために問題を解決していませんでした。

This discussionは、文字列から派生したクラスを変更することを提案しています(私はいくつかの場所でコードを認識しています)。これで問題は解決しました。

関連する問題