0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[VScode]OpenCV Cppで環境構築しようとして詰まった点と解決策

Posted at

導入

この記事に書いてあることは題名の通りです。
他qiitaやzennで調べながらopencv cppで環境構築しようとして詰まったところ書いておきます。
8割方備忘録のようなモノです。
構築するときに使わせていただいたサイトは一番下に載せておきます。
是非活用してください。

本題

まず一つ目です。
まずopencvソースコードのビルドについてです。
事前にmkdirで生成ファイルを吐き出すフォルダを作成しておきます。
その後ビルドするには、

terminal
cmake -S . -B (mkdirで作成したフォルダ名)

と実行するとエラーを吐く方が居ると思います。俺はそれでした。

エラー内容
-- Building for: Visual Studio 17 2022
-- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.22631.
-- The C compiler identification is MSVC 19.42.34436.0
-- The CXX compiler identification is MSVC 19.42.34436.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/14.42.34433/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/14.42.34433/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:4 (find_package):
  By not providing "FindOpenCV.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "OpenCV", but
  CMake did not find one.

  Could not find a package configuration file provided by "OpenCV" with any
  of the following names:

    OpenCVConfig.cmake
    opencv-config.cmake

  Add the installation prefix of "OpenCV" to CMAKE_PREFIX_PATH or set
  "OpenCV_DIR" to a directory containing one of the above files.  If "OpenCV"
  provides a separate development package or SDK, be sure it has been
  installed.


-- Configuring incomplete, errors occurred!

エラー内容はOpenCVConfig.cmakeとopencv-config.cmakeが見つからないとのことです。
原因はCMakeLists.txtはopencv/sourcesにあるのですが、OpenCVconfig, opencv-config.cmakeはopencv/buildにあります。
それを解決するために、-S オプションの後にCMakeLists.txtの位置を指定してあげます。

terminal
cmake -S opencv/sources -B

生成ファイルを吐き出すフォルダがopencvにあるなら上記のコードで正常にビルドできるはずです。
場所が違うなら、-B オプションの後に同じように位置を指定してあげてください。

環境構築の際使わせていただいたサイト

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?