不知道如何为MinGW构建OpenCV

Vor*_*rac 3 c++ opencv cmake

TL; DR;

我正在尝试为MinGW构建OpenCV.cmake虽然我可以使用g ++.exe编译示例代码,但仍然抱怨没有理智的CXX编译器.


长版

我尝试为MinGW找到一个二进制文件,但这不起作用.

我尝试编译MinGW,但是因为sh.exe在路径中的一些错误而失败了.我很困惑,因为重命名文件系统上的目标文件并没有解决问题.

E:\work\opencv\mybuild> cmake -G "MinGW Makefiles" ../sources
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeMin
GWFindMake.cmake:22 (message):
  sh.exe was found in your PATH, here:


  C:/Users/desuna/AppData/Local/GitHub/PortableGit_054f2e797ebafd44a30203088cd3d
58663c627ef/bin/sh.exe


  For MinGW make to work correctly sh.exe must NOT be in your path.

  Run cmake from a shell that does not have sh.exe in your PATH.

  If you want to use a UNIX shell, then use MSYS Makefiles.

Call Stack (most recent call first):
  CMakeLists.txt:56 (project)


CMake Error: CMake was unable to find a build program corresponding to "MinGW Ma
kefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a differe
nt build tool.
CMake Error: CMake was unable to find a build program corresponding to "MinGW Ma
kefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a differe
nt build tool.
CMake Error: Error required internal CMake variable not set, cmake may be not be
 built correctly.
Missing variable is:
CMAKE_CXX_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may be not be
 built correctly.
Missing variable is:
CMAKE_CXX_COMPILER
CMake Error: Could not find cmake module file: E:/work/opencv/mybuild/CMakeFiles
/2.8.12.2/CMakeCXXCompiler.cmake
CMake Error: Error required internal CMake variable not set, cmake may be not be
 built correctly.
Missing variable is:
CMAKE_C_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may be not be
 built correctly.
Missing variable is:
CMAKE_C_COMPILER
CMake Error: Could not find cmake module file: E:/work/opencv/mybuild/CMakeFiles
/2.8.12.2/CMakeCCompiler.cmake
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
Run Code Online (Sandbox Code Playgroud)

后来我被告知,MSYS makefile没有这个要求.现在有一个关于C++编译器的错误.但是,正确识别了C++编译器.此外,我尝试编译一个虚拟test.cxx程序,它的工作原理.

E:\work\opencv\mybuild> cmake -G "MSYS Makefiles" ../sources
-- The CXX compiler identification is GNU 4.8.1
-- The C compiler identification is GNU 4.8.1
-- Check for working CXX compiler: C:/MinGW/bin/g++.exe
-- Check for working CXX compiler: C:/MinGW/bin/g++.exe -- broken
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeTes
tCXXCompiler.cmake:54 (message):
  The C++ compiler "C:/MinGW/bin/g++.exe" is not able to compile a simple
  test program.

  It fails with the following output:

   Change Dir: E:/work/opencv/mybuild/CMakeFiles/CMakeTmp
Run Code Online (Sandbox Code Playgroud)

错误日志是:

Determining if the CXX compiler works failed with the following output:
Change Dir: E:/work/opencv/mybuild/CMakeFiles/CMakeTmp

Run Build Command:C:/PROGRA~2/GnuWin32/bin/make.exe "cmTryCompileExec1507552824/fast"
C:/PROGRA~2/GnuWin32/bin/make.exe -f CMakeFiles/cmTryCompileExec1507552824.dir/build.make CMakeFiles/cmTryCompileExec1507552824.dir/build

make.exe[1]: Entering directory `E:/work/opencv/mybuild/CMakeFiles/CMakeTmp'

"/C/Program Files (x86)/CMake 2.8/bin/cmake.exe" -E cmake_progress_report /E/work/opencv/mybuild/CMakeFiles/CMakeTmp/CMakeFiles 1

Building CXX object CMakeFiles/cmTryCompileExec1507552824.dir/testCXXCompiler.cxx.obj
/C/MinGW/bin/g++.exe     -o CMakeFiles/cmTryCompileExec1507552824.dir/testCXXCompiler.cxx.obj -c /E/work/opencv/mybuild/CMakeFiles/CMakeTmp/testCXXCompiler.cxx

process_begin: CreateProcess(NULL, /C/MinGW/bin/g++.exe -o CMakeFiles/cmTryCompileExec1507552824.dir/testCXXCompiler.cxx.obj -c /E/work/opencv/mybuild/CMakeFiles/CMakeTmp/testCXXCompiler.cxx, ...) failed.

make (e=2): The system cannot find the file specified.


make.exe[1]: *** [CMakeFiles/cmTryCompileExec1507552824.dir/testCXXCompiler.cxx.obj] Error 2

make.exe[1]: Leaving directory `E:/work/opencv/mybuild/CMakeFiles/CMakeTmp'

make.exe: *** [cmTryCompileExec1507552824/fast] Error 2
Run Code Online (Sandbox Code Playgroud)

我的目标是在Windows 7下为C++中的小应用程序进行一步构建,链接到onecv_core,opencv_highgui等等.为此,似乎我需要在mingw下使用gcc从源代码构建OpenCV.请告知正确的方法是什么.


编辑:

我尝试了barek的答案,错误与MSYS目标相同 - 没有理智的c ++编译器.我接下来尝试cmake-gui,指定编译器.另外,我确保MinGW/bin在我的路上.按照错误消息:

CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER_ENV_VAR
CMake Error: Could not find cmake module file: E:/work/opencv/mybuild/CMakeFiles/2.8.12.2/CMakeCXXCompiler.cmake
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER_ENV_VAR
CMake Error: Could not find cmake module file: E:/work/opencv/mybuild/CMakeFiles/2.8.12.2/CMakeCCompiler.cmake
Configuring incomplete, errors occurred!
Run Code Online (Sandbox Code Playgroud)

我怀疑问题在于一些非常愚蠢的事情,比如CMAKE无法改变目录,因为MinGW isciplation不合适.

在这里可以找到讨论,但我:

  • 检查MinGW/bin是否在我的路径中
  • 还手动指定了C和C++编译器路径 cmake-gui
  • 使用SourceForge中的安装程序安装MinGW并选中复选框"Alter PATH".

ber*_*rak 9

  1. 清理!删除所有以前的构建尝试CmakeFile.cache,等等.

  2. 有MingW/bin在路上

  3. 使OpenCV的目录中的文件夹,名为build_mingw,cd

  4. cmake -G "MinGW Makefiles" -D CMAKE_CXX_COMPILER=mingw32-g++.exe -D CMAKE_MAKE_PROGRAM=mingw32-make.exe .. #< - 注意最后的点

  5. mingw32-make

  6. mingw32-make install