外部ヘッダファイルのクラス・関数が未解決

フォーラム(掲示板)ルール
フォーラム(掲示板)ルールはこちら  ※コードを貼り付ける場合は [code][/code] で囲って下さい。詳しくはこちら
アバター
MoNoQLoREATOR
記事: 284
登録日時: 15年前
住所: 東京

外部ヘッダファイルのクラス・関数が未解決

#1

投稿記事 by MoNoQLoREATOR » 14年前

プロジェクトに追加していないヘッダファイルをインクルードして、そこで定義されているクラスや関数を使おうとすると、未解決(リンクエラー)であると言われてしまいました。

とりあえず関係のあるものを全てフォルダにまとめてUPしました。
http://www1.axfc.net/uploader/H/so/157081&key=projects

①クラス・関数の定義が書かれたヘッダファイルを任意の数だけ作成する
②その全てのヘッダファイルをインクルードするだけのヘッダファイル(まとめヘッダファイル)を作成する
③まとめヘッダファイルをインクルードする
上記の操作を行うことで、既存のクラスや関数の使いまわしを実現していたのですが、突然、昨日からリンクエラーを吐き出すようになりました。
統合開発環境はVisualC++2008(無料版)です。

関数については、
#define FW_WIN_MAIN_
が定義されていれば実体を定義し、そうでなければプロトタイプ宣言を行う仕様となっており、WinMain関数の定義が書かれているファイルでのみ「まとめヘッダファイルをインクルードする前に例のマクロを定義する」ことで、関数の実体定義を1回のみにおさえる仕組みになっています。(もちろんWinMainがあるファイルでなくとも、どこか一箇所だけにマクロを定義すれば良いが、わかりやすさのため。)

実験を行なったところ、まとめファイルのインクルードを一箇所だけにおさえることができればリンクエラーは出ませんでした。
複数の場所でインクルードするとリンクエラーが出るようです。

ちなみに、実際に吐き出されたエラーは下記の通りで、プロジェクト内容は「独自形式ファイルの解凍」です。

コード:

------ ビルド開始: プロジェクト: fwmDecoder, 構成: Debug Win32 ------
コンパイルしています...
WinMain.cpp
コードを生成中...
コンパイル中...
Accept.cpp
Dispose.cpp
Info.cpp
MainLoop.cpp
OutPut.cpp
コードを生成中...
リンクしています...
Accept.obj : error LNK2019: 未解決の外部シンボル "class fw::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > __cdecl fw::onlyfile(class fw::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > const &)" (?onlyfile@fw@@YA?AV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@1@ABV21@@Z) が関数 "bool __cdecl Accept(class fw::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > &)" (?Accept@@YA_NAAV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@fw@@@Z) で参照されました。
Accept.obj : error LNK2001: 外部シンボル ""public: static struct fw::fordepth const fw::depth::deep" (?deep@depth@fw@@2Ufordepth@2@B)" は未解決です。
Accept.obj : error LNK2001: 外部シンボル ""public: static struct fw::forpathatt const fw::pathatt::file" (?file@pathatt@fw@@2Uforpathatt@2@B)" は未解決です。
Accept.obj : error LNK2019: 未解決の外部シンボル "class fw::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > __cdecl fw::onlydire(class fw::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > const &)" (?onlydire@fw@@YA?AV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@1@ABV21@@Z) が関数 "bool __cdecl Accept(class fw::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > &)" (?Accept@@YA_NAAV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@fw@@@Z) で参照されました。
Accept.obj : error LNK2001: 外部シンボル ""public: static struct fw::forpathatt const fw::pathatt::all" (?all@pathatt@fw@@2Uforpathatt@2@B)" は未解決です。
Accept.obj : error LNK2001: 外部シンボル ""public: static struct fw::fordepth const fw::depth::shallow" (?shallow@depth@fw@@2Ufordepth@2@B)" は未解決です。
Accept.obj : error LNK2001: 外部シンボル ""public: static struct fw::fordepth const fw::depth::deepest" (?deepest@depth@fw@@2Ufordepth@2@B)" は未解決です。
Accept.obj : error LNK2019: 未解決の外部シンボル "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl fw::onlyextend(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?onlyextend@fw@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV23@@Z) が関数 "private: void __thiscall fw::path::dispose(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?dispose@path@fw@@AAEXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) で参照されました。
Accept.obj : error LNK2001: 外部シンボル ""public: static struct fw::forpathatt const fw::pathatt::dire" (?dire@pathatt@fw@@2Uforpathatt@2@B)" は未解決です。
Info.obj : error LNK2019: 未解決の外部シンボル "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl fw::onlyname(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?onlyname@fw@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV23@@Z) が関数 "void __cdecl Info(struct fw::ProData const &,struct fw::ProData const &,class fw::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > const &,unsigned int)" (?Info@@YAXABUProData@fw@@0ABV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@I@Z) で参照されました。
MainLoop.obj : error LNK2019: 未解決の外部シンボル "bool __cdecl Dispose(class fw::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > const &)" (?Dispose@@YA_NABV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@fw@@@Z) が関数 "int __cdecl MainLoop(void)" (?MainLoop@@YAHXZ) で参照されました。
OutPut.obj : error LNK2019: 未解決の外部シンボル "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl fw::gratype(class fw::vector<unsigned char> const &)" (?gratype@fw@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV?$vector@E@1@@Z) が関数 "unsigned long __stdcall OutPut(void *)" (?OutPut@@YGKPAX@Z) で参照されました。
OutPut.obj : error LNK2019: 未解決の外部シンボル "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl fw::root(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?root@fw@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV23@@Z) が関数 "unsigned long __stdcall OutPut(void *)" (?OutPut@@YGKPAX@Z) で参照されました。
C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\fwmDecoder\Debug\fwmDecoder.exe : fatal error LNK1120: 外部参照 13 が未解決です。
ビルドログは "file://c:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\fwmDecoder\Debug\BuildLog.htm" に保存されました。
fwmDecoder - エラー 14、警告 0
========== ビルド: 0 正常終了、1 失敗、0 更新不要、0 スキップ ==========

ご教授よろしくお願い致します。

beatle
記事: 1281
登録日時: 14年前
住所: 埼玉
連絡を取る:

Re: 外部ヘッダファイルのクラス・関数が未解決

#2

投稿記事 by beatle » 14年前

インライン関数は、ヘッダファイルに定義を書いて置かなければなりません。なぜなら、コンパイル時に関数呼び出しの場所に関数を埋め込まねばならないからです。
例えばfireworks/StandardEdition/path.hには沢山のインライン関数の定義とプロトタイプ宣言があり、それらをFW_WIN_MAIN_マクロの定義の有無で切り替えています。しかし、インライン関数の場合は常に定義を書いて置かなければなりませんから、マクロによる切り替えをしてはいけません。

アバター
MoNoQLoREATOR
記事: 284
登録日時: 15年前
住所: 東京

Re: 外部ヘッダファイルのクラス・関数が未解決

#3

投稿記事 by MoNoQLoREATOR » 14年前

>>beatleさん
返信ありがとうございます。
インライン関数にはそんなルールがあったのですか。なるほど、たしかにそうでないと無理がありますよね。勉強になりました。

インライン関数を実体定義のみするとエラーはでなくなりました。
ありがとうございました。

閉鎖

“C言語何でも質問掲示板” へ戻る