質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
MFC

MFC (Microsoft Fouondation Class)とは、MicrosoftがVC++用に開発したWindows用アプリケーションのフレームワークです。

Visual Studio

Microsoft Visual StudioはMicrosoftによる統合開発環境(IDE)です。多種多様なプログラミング言語に対応しています。

OpenCV

OpenCV(オープンソースコンピュータービジョン)は、1999年にインテルが開発・公開したオープンソースのコンピュータビジョン向けのクロスプラットフォームライブラリです。

Q&A

解決済

1回答

3458閲覧

MFCアプリケーションを用いたopencvの導入

matusnaga_k

総合スコア3

MFC

MFC (Microsoft Fouondation Class)とは、MicrosoftがVC++用に開発したWindows用アプリケーションのフレームワークです。

Visual Studio

Microsoft Visual StudioはMicrosoftによる統合開発環境(IDE)です。多種多様なプログラミング言語に対応しています。

OpenCV

OpenCV(オープンソースコンピュータービジョン)は、1999年にインテルが開発・公開したオープンソースのコンピュータビジョン向けのクロスプラットフォームライブラリです。

0グッド

0クリップ

投稿2019/08/15 20:09

前提・実現したいこと

プログラミング初心者です。貰ったソースファイル(MFC)からopencvを加えて作業を行おうした所、opencvをインクルードすることが出来ましたが、次ようなエラーが出てしまい、コンパイルすることが出来ません。どのようにすれば通るようになりますか。お願い致します。

実装中に以下のエラーメッセージが発生しました。

エラーメッセージ LNK2019 未解決の外部シンボル "void __cdecl cv::fastFree(void *)" (?fastFree@cv@@YAXPAX@Z) が関数 "public: __thiscall cv::Mat::~Mat(void)" (??1Mat@cv@@QAE@XZ) で参照されました。 OmniWhlCtrl ### 該当のソースコード ```C++ // OmniWhlCtrlDlg.cpp : 実装ファイル // #include "stdafx.h" #include "OmniWhlCtrl.h" #include "OmniWhlCtrlDlg.h" #include ".\omniwhlctrldlg.h" #include <opencv2/opencv.hpp> #include "SetComDlg.h" using namespace cv; Mat im(Size(300, 300), CV_8UC3, Scalar(0, 255, 255));←ここにエラーが発生してしまいます。 #ifdef _DEBUG #define new DEBUG_NEW #endif

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

C++はヘッダを参照することで定義を取り込み(インクルード)、.libを参照することで実体(実装)を取り込みます(リンク)。というわけで、cv::fastFree(void *)を含むlibファイルをリンクしなければいけません。
OpenCVのバージョンもわからないのでこのファイル!とかは言えないですが、とりあえず目についたlibをリンクしてみたらエラーは出なくなるかもしれません。

OpenCVビルド方法

投稿2019/08/15 23:58

編集2019/08/16 01:42
moredeep

総合スコア1507

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

matusnaga_k

2019/08/16 00:27

質問漏れ、申し訳ありません。 opencvのバージョンはopencv4.1.1-vc14_15です。
moredeep

2019/08/16 00:59

OpenCVを展開したフォルダ\build\x64\vc15\lib\opencv_world411.libをリンクしてみてください。
matusnaga_k

2019/08/16 01:04

リンクの仕方は、「共通プロパティ」→「リンカー」→「入力」で追加の依存ファイルにリンクすればよいですか。
moredeep

2019/08/16 01:10 編集

「リンカー」->「全般」の「追加のライブラリディレクトリ」にディレクトリを設定し、 「リンカー」->「入力」の「追加の依存ファイル」にファイル名を設定すればOKです。
matusnaga_k

2019/08/16 01:24

行ったのですが、引き続きエラーが発生してしまいます。
matusnaga_k

2019/08/16 01:36

参考になればと思うのですが、次のような警告も発生してしまいます。 LNK4272 ライブラリのコンピューターの種類 'x64' がターゲットのコンピューターの種類' x86' と競合しています OmniWhlCtrl C:\Users\matsuken92\Downloads\opencv\build\x64\vc15\lib\opencv_world411.lib
moredeep

2019/08/16 01:41

あぁ、x86だったんですね。 であれば、x86のopencv_world411.libにリンクしないといけないですが、x86は最初は含まれていないので、自分でビルドする必要があります。
moredeep

2019/08/16 01:45

ビルド方法の参考ブログを張りましたが、注意点 ・64bitと32bitの選択のところで必ず32bitを選ぶこと ・opencv_worldが欲しいので設定を行うこと(BUILD_opencv_worldにチェックってとこ)
matusnaga_k

2019/08/16 01:51

「共通プロパティ」→「リンカー」→「詳細設定」対象のコンピュータをMachineX64 に変更すると、モジュールのコンピューターの種類 'x86' は対象コンピューターの種類 'x64' と競合しています。となってしまうのですが、自分でビルドする方法の仕方は教えて頂きますでしょうか。
matusnaga_k

2019/08/16 02:18

わかりました、指摘された点に注意して行ってみます。
matusnaga_k

2019/08/16 09:30

書かれたOPENCVをCMakeで生成した所次のような、エラーが発生してしまいました。 Warning (dev) at apps/haartraining/CMakeLists.txt:34 (add_library): Policy CMP0038 is not set: Targets may not link directly to themselves. Run "cmake --help-policy CMP0038" for policy details. Use the cmake_policy command to set the policy and suppress this warning. Target "opencv_haartraining_engine" links to itself. This warning is for project developers. Use -Wno-dev to suppress it. CMake Warning (dev) at apps/haartraining/CMakeLists.txt:34 (add_library): Policy CMP0038 is not set: Targets may not link directly to themselves. Run "cmake --help-policy CMP0038" for policy details. Use the cmake_policy command to set the policy and suppress this warning. Target "opencv_haartraining_engine" links to itself. This warning is for project developers. Use -Wno-dev to suppress it. CMake Error: install(EXPORT "OpenCVModules" ...) includes target "opencv_world" which requires target "zlib" that is not in the export set. CMake Error: install(EXPORT "OpenCVModules" ...) includes target "opencv_world" which requires target "zlib" that is not in the export set. CMake Error: install(EXPORT "OpenCVModules" ...) includes target "opencv_world" which requires target "libjpeg" that is not in the export set. CMake Error: install(EXPORT "OpenCVModules" ...) includes target "opencv_world" which requires target "libpng" that is not in the export set. CMake Error: install(EXPORT "OpenCVModules" ...) includes target "opencv_world" which requires target "libtiff" that is not in the export set. CMake Error: install(EXPORT "OpenCVModules" ...) includes target "opencv_world" which requires target "libjasper" that is not in the export set. CMake Error: install(EXPORT "OpenCVModules" ...) includes target "opencv_world" which requires target "IlmImf" that is not in the export set. CMake Error: install(EXPORT "OpenCVModules" ...) includes target "opencv_world" which requires target "zlib" that is not in the export set. CMake Error: install(EXPORT "OpenCVModules" ...) includes target "opencv_world" which requires target "zlib" that is not in the export set. CMake Error: install(EXPORT "OpenCVModules" ...) includes target "opencv_world" which requires target "libjpeg" that is not in the export set. CMake Error: install(EXPORT "OpenCVModules" ...) includes target "opencv_world" which requires target "libpng" that is not in the export set. CMake Error: install(EXPORT "OpenCVModules" ...) includes target "opencv_world" which requires target "libtiff" that is not in the export set. CMake Error: install(EXPORT "OpenCVModules" ...) includes target "opencv_world" which requires target "libjasper" that is not in the export set. CMake Error: install(EXPORT "OpenCVModules" ...) includes target "opencv_world" which requires target "IlmImf" that is not in the export set. CMake Warning (dev) at apps/haartraining/CMakeLists.txt:34 (add_library): Policy CMP0038 is not set: Targets may not link directly to themselves. Run "cmake --help-policy CMP0038" for policy details. Use the cmake_policy command to set the policy and suppress this warning. Target "opencv_haartraining_engine" links to itself. This warning is for project developers. Use -Wno-dev to suppress it. このようなところで手詰まりを起こしています。もし、よろしければご回答お願いします。
moredeep

2019/08/19 06:52

遅くなってすみません、何度か頑張ったのですが、再現できず。。。 もし可能なら、ビルド構成をx64にすれば既に存在するもので問題なくリンクできるので、そちらを試してみてもいいかもしれません。(変えるのは、ビルドしたいMFCベースのやつです。Any CPUかWin32かx86のどれかになっていると思うので、x64にすればOKなはずです。) 不可ならば、とりあえずどの手順でどこにそのエラーが出ているのか教えていただければと思います。
matusnaga_k

2019/08/19 11:59

わざわざご回答ありがとうございます。言われた通り、ビルド構成をx64にして既に存在するものでビルドを行ったところ、Moduleファイル内の所で エラー (アクティブ) E1696 ソース ファイルを開けません "stdafx.h" OmniWhlCtrl C:\Users\matsuken92\source\repos\OmniWhlCtrl_V2000\Module\KThread.cpp 11 エラー (アクティブ) E0020 識別子 "GWL_WNDPROC" が定義されていません OmniWhlCtrl C:\Users\matsuken92\source\repos\OmniWhlCtrl_V2000\Module\KThread.cpp 92 となってしまいました。どのようにすればよろしいでしょうか。
matusnaga_k

2019/08/19 12:19

C:\Users\matsuken92\source\repos\OmniWhlCtrl_V2000\Module内の.cppファイルの"stdafx.h"が開けない状況になっています。
matusnaga_k

2019/08/19 12:37

stdafx.hはModule内にstdafx.cppとstdafx.hを作り解決しましたが、 E0020 識別子 "GWL_WNDPROC" が定義されていません OmniWhlCtrl C:\Users\matsuken92\source\repos\OmniWhlCtrl_V2000\Module\KThread.cpp 92 とのエラーが発生しています。
matusnaga_k

2019/08/19 17:45 編集

もし、よかったらソースファイルを何らかの形でお渡ししても大丈夫です。
moredeep

2019/08/20 01:31

GWL_WNDPROCはx64では削除されるようです。 差し当たり、stdafx.hの初めに #define GWL_WNDPROC (-4) とすればそのエラーは出なくなるかと思います。 ただし、似たエラーが頻発する可能性があるうえ、x86しか想定していない実装があった場合に動作がおかしくなる可能性もあるので、やはり、x86でどうにかする方がいいかもしれませんね。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問