2009-03-02 7 views
11

私は複数のプロジェクトを持つソリューションを持っています。私はメニューとして機能する「メイン」プロジェクトを持っており、そこから他のプロジェクトにアクセスすることができます。このメインプロジェクトでは、呼び出されるすべての関数のリンカーエラーが発生します。これらのリンカーエラーを回避するにはどうすればよいですか?私は既にプロジェクト依存関係を "Project Dependencies ..."ダイアログに設定しています。Visual C++での複数のプロジェクト間のリンカーエラー

おかげ

EDIT - 私が示唆したように行なったし、リンカの追加のディレクトリに出力フォルダを追加しました。さて、次のようにしかし、私は万人のエラーを取得:

3>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: void __thiscall std::basic_ios >::setstate(int,bool)" ([email protected][email protected][email protected]@[email protected]@@[email protected]@[email protected]) already defined in panels.lib(panel_main.obj) 
3>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: int __thiscall std::ios_base::width(int)" ([email protected][email protected]@@[email protected]) already defined in panels.lib(panel_main.obj) 
3>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: int __thiscall std::basic_streambuf >::sputn(char const *,int)" ([email protected][email protected][email protected]@[email protected]@@[email protected]@[email protected]) already defined in panels.lib(panel_main.obj) 
3>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: static bool __cdecl std::char_traits::eq_int_type(int const &,int const &)" ([email protected][email protected]@[email protected]@[email protected]) already defined in panels.lib(panel_main.obj) 
3>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: static int __cdecl std::char_traits::eof(void)" ([email protected][email protected]@[email protected]@SAHXZ) already defined in panels.lib(panel_main.obj) 
3>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: int __thiscall std::basic_streambuf >::sputc(char)" ([email protected][email protected][email protected]@[email protected]@@[email protected]@[email protected]) already defined in panels.lib(panel_main.obj) 
3>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: class std::basic_streambuf > * __thiscall std::basic_ios >::rdbuf(void)const " ([email protected][email protected][email protected]@[email protected]@@[email protected]@[email protected][email protected]@[email protected]@@[email protected]) already defined in panels.lib(panel_main.obj) 
3>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: char __thiscall std::basic_ios >::fill(void)const " ([email protected][email protected][email protected]@[email protected]@@[email protected]@QBEDXZ) already defined in panels.lib(panel_main.obj) 
3>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: int __thiscall std::ios_base::flags(void)const " ([email protected][email protected]@@QBEHXZ) already defined in panels.lib(panel_main.obj) 
3>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: int __thiscall std::ios_base::width(void)const " ([email protected][email protected]@@QBEHXZ) already defined in panels.lib(panel_main.obj) 
3>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: static unsigned int __cdecl std::char_traits::length(char const *)" ([email protected][email protected]@[email protected]@[email protected]) already defined in panels.lib(panel_main.obj) 
3>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: class std::basic_ostream > & __thiscall std::basic_ostream >::flush(void)" ([email protected][email protected][email protected]@[email protected]@@[email protected]@[email protected]) already defined in panels.lib(panel_main.obj) 
3>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: class std::basic_ostream > * __thiscall std::basic_ios >::tie(void)const " ([email protected][email protected][email protected]@[email protected]@@[email protected]@[email protected][email protected]@[email protected]@@[email protected]) already defined in panels.lib(panel_main.obj) 
3>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: bool __thiscall std::ios_base::good(void)const " ([email protected][email protected]@@QBE_NXZ) already defined in panels.lib(panel_main.obj) 
3>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: void __thiscall std::basic_ostream >::_Osfx(void)" ([email protected][email protected][email protected]@[email protected]@@[email protected]@QAEXXZ) already defined in panels.lib(panel_main.obj) 
3>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: void __thiscall std::basic_streambuf >::_Lock(void)" ([email protected][email protected][email protected]@[email protected]@@[email protected]@QAEXXZ) already defined in panels.lib(panel_main.obj) 
3>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: void __thiscall std::basic_streambuf >::_Unlock(void)" ([email protected][email protected][email protected]@[email protected]@@[email protected]@QAEXXZ) already defined in panels.lib(panel_main.obj) 
3>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: class std::locale::facet * __thiscall std::locale::facet::_Decref(void)" ([email protected]@[email protected]@@[email protected]) already defined in panels.lib(panel_main.obj) 
3>libcpmtd.lib(ios.obj) : error LNK2005: "private: static void __cdecl std::ios_base::_Ios_base_dtor(class std::ios_base *)" ([email protected][email protected]@@[email protected]@Z) already defined in msvcprtd.lib(MSVCP90D.dll) 
3>libcpmtd.lib(ios.obj) : error LNK2005: "public: static void __cdecl std::ios_base::_Addstd(class std::ios_base *)" ([email protected][email protected]@@[email protected]@Z) already defined in msvcprtd.lib(MSVCP90D.dll) 
3>libcpmtd.lib(locale0.obj) : error LNK2005: "void __cdecl _AtModuleExit(void (__cdecl*)(void))" ([email protected]@[email protected]) already defined in msvcprtd.lib(locale0_implib.obj) 
3>libcpmtd.lib(locale0.obj) : error LNK2005: __Fac_tidy already defined in msvcprtd.lib(locale0_implib.obj) 
3>libcpmtd.lib(locale0.obj) : error LNK2005: "private: static void __cdecl std::locale::facet::facet_Register(class std::locale::facet *)" ([email protected]@[email protected]@@[email protected]@Z) already defined in msvcprtd.lib(locale0_implib.obj) 
3>libcpmtd.lib(locale0.obj) : error LNK2005: "private: static class std::locale::_Locimp * __cdecl std::locale::_Getgloballocale(void)" ([email protected]@[email protected]@[email protected]@XZ) already defined in msvcprtd.lib(MSVCP90D.dll) 
3>libcpmtd.lib(locale0.obj) : error LNK2005: "private: static class std::locale::_Locimp * __cdecl std::locale::_Init(void)" ([email protected]@[email protected]@[email protected]@XZ) already defined in msvcprtd.lib(MSVCP90D.dll) 
3>libcpmtd.lib(locale0.obj) : error LNK2005: "public: static void __cdecl std::_Locinfo::_Locinfo_ctor(class std::_Locinfo *,class std::basic_string,class std::allocator > const &)" ([email protected][email protected]@@[email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@Z) already defined in msvcprtd.lib(MSVCP90D.dll) 
3>libcpmtd.lib(locale0.obj) : error LNK2005: "public: static void __cdecl std::_Locinfo::_Locinfo_dtor(class std::_Locinfo *)" ([email protected][email protected]@@[email protected]@Z) already defined in msvcprtd.lib(MSVCP90D.dll) 
3>libcpmtd.lib(xlock.obj) : error LNK2005: "public: __thiscall std::_Lockit::_Lockit(int)" ([email protected]@@[email protected]@Z) already defined in msvcprtd.lib(MSVCP90D.dll) 
3>libcpmtd.lib(xlock.obj) : error LNK2005: "public: __thiscall std::_Lockit::~_Lockit(void)" ([email protected]@@[email protected]) already defined in msvcprtd.lib(MSVCP90D.dll) 

答えて

11

ソリューションに関するその他の詳細を知らなくても、伝えるのは難しいです、しかし、すべてを再構築し、役に立つかもしれません。この状況は、アーキテクチャーごとにオブジェクトファイルが混在している場合に発生することがあります。

はまた、代わりに「依存」の「参照」を使用して検討することをお勧めします

EDIT:あなたは標準ライブラリにあなたの結合が矛盾しているようだ投稿したものを後

。プロジェクトの1つが標準ライブラリを静的にリンクし、他のものを動的にリンクすることができますか? (プロジェクトのプロパティ - >リンカを参照してください)または1つはリリースランタイムに、もう1つはデバッグしますか? (最後のものは注意が必要ですが)

+0

参考資料は.NETプロジェクトでのみ使用されていると思います。 OPはこれとは別の方法を述べていないが、私は彼がアンマネージドC++で書いていると思うだろう。 – Andy

+0

私はアンマネージドC++でリファレンスを使用していますが、完全に動作します。 – EFraim

+3

矛盾したリンケージ(/ MT対/ MD)に言及してくれてありがとう。私はそれを考えず、この一貫性をつけてLNK2005のエラーを解決しました。 –

0

"未解決のシンボル"になっていると思われるリンカエラーはありますか?

スタティックライブラリ(.libファイル)を使用している場合、リンク時にシンボルをリンクできるように、ライブラリをリンカ入力に追加する必要があります。これをしないと、未解決のシンボルが表示されます。

  1. プロジェクトを右クリックし、[プロパティ]を選択します。
  2. 設定プロパティ - >リンカ - >入力を選択
  3. 追加の依存関係の下にライブラリ名(例:filename.lib)を入力します。
+1

Visual Studioでプロジェクト依存関係を追加すると、自動的にプロジェクトの出力にリンクされます(ただし、.libはプロパティに追加されません)。 – Andy

2

他のプロジェクトの機能はエクスポートされていますか?それらがエクスポートされていない場合は、メインEXEからリンクするものがないので、エラーが発生します。詳細については、Exporting from a DLL Using __declspec(export)を参照してください。

20

解決策の詳細がわからないと答えにくいですが、 "other"プロジェクトが.libファイルを生成するように設定されていると仮定し、メインプロジェクトがこれらのlibファイルをリンクしているとします。この場合、エラーが発生する原因として、プロジェクトが異なるバージョンのランタイムライブラリにリンクしている可能性があります。

Microsoft's documentation "リンカの呼び出しに渡されたすべてのモジュールは、同じランタイムライブラリコンパイラオプション(/ MD、/ MT、/ LD)でコンパイルされている必要があります。

すべてのプロジェクトを同じバージョンのランタイムライブラリを使用するように変更してください。 Visual Studio 2010では、これはプロジェクトのプロパティ|構成プロパティ| C/C++ |コード生成|ランタイムライブラリ。 マルチスレッドデバッグDLLまたはマルチスレッドデバッグ(デバッグ構成の場合)を選択します。

+0

ありがとう、Dani!私はこの問題を抱えており、あなたのソリューションは正しかった。私の静的ライブラリのランタイムライブラリは "マルチスレッドデバッグ"に設定されていましたが、それにリンクするアプリケーションは "マルチスレッドデバッグDLL"に設定されていました。ランタイムライブラリの設定を変更して、一致したすべてがリンカエラーを修正しました。 – vocaro

+0

これは私の失敗を引き起こしていました。ありがとうございます – rinormaloku

1

あなたが得ているエラーは、リンクしているライブラリのシンボル(msvcprtd.lib)が別のライブラリ(例えばpanels.lib)で定義されている「エラーLNK2005」です。 「特定のライブラリを無視する」フィールド(VS2008構成プロパティ - >リンカ - >入力 - >特定のライブラリを無視する)にpanels.libを追加すると、エラーは停止します。

0

これは非常によく似た問題でしたが、私のライブラリの1つに 'wchar_tを組み込み型として扱う'というオプションが他のライブラリとは異なる値に設定されていたためです。この設定は、新規プロジェクトではデフォルトではfalseです。それらをすべて真に変更することで問題は解決されました。

0

正確には、少なくとも1つのプロジェクトが別の「ランタイムライブラリ」でコンパイルされています。たぶんあなたは違うデフォルトを使って新しいものを追加しました。 "構成プロパティ" - > "C/C++" - > "コード生成" - > "ランタイムライブラリ"という同じ値のプロジェクトのプロパティを確認してください。

+0

Dani van der Meerが3年前に言ったことはまったくありませんか? –

0

私の場合、問題は、関数プロトタイプ、クラス定義、関数実装、クラス実装を1つのcppファイルに保存していたためです。宣言とプロトタイプを別のヘッダファイルに移したときにだけ、これらのエラーは消えました。本当に変だ!

関連する問題