问题描述
TL;DR;
我正在尝试为 MinGW 构建 OpenCV.cmake
一直抱怨没有健全的 CXX 编译器,尽管我可以用 g++.exe 编译示例代码.
I am trying to build OpenCV for MinGW. cmake
keeps complaining about no sane CXX compiler, although I can compile sample code with g++.exe.
长版
我尝试为 MinGW 找到一个二进制文件,但这没有用.
I tried finding a binary for MinGW, but this didn't work.
我尝试为 MinGW 编译,但由于 sh.exe 不在 $PATH 中出现一些错误而失败.我很困惑,因为在文件系统上重命名目标文件并没有解决问题.
I tried compiling for MinGW but that fails with some error about sh.exe not being in $PATH. I am puzzled, as renaming the target file on the filesystem did not resolve the issue.
E:workopencvmybuild> 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!
后来有人告诉我,MSYS 生成文件没有这个要求.现在有关于 C++ 编译器的错误.但是,C++ 编译器被正确识别.另外,我尝试编译了一个虚拟的 test.cxx 程序,并且成功了.
I was advised later, that MSYS makefiles do not have this requirement. Now there was an error about the C++ compiler. However, the C++ compiler is correctly identified. Also, I tried compiling a dummy test.cxx program and it worked.
E:workopencvmybuild> 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
错误日志是:
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
我的目标是在 Windows 7 下为 C++ 中的小型应用程序进行一步构建,该应用程序链接到 onecv_core、opencv_highgui 等.为此,我似乎需要在 mingw 下使用 gcc 从源代码构建 OpenCV.请告知正确的方法是什么.
My aim is to have one-step build under Windows 7 for a small application in C++, that links against onecv_core, opencv_highgui and several more. For this, it appears that I need to build OpenCV from source with gcc under mingw. Please advise what is the correct approach to that.
我尝试了 barek 的答案,错误与 MSYS 目标相同 - 没有健全的 C++ 编译器.我接下来尝试了 cmake-gui
,指定编译器.另外,我确保 MinGW/bin 在我的路径中.遵循错误消息:
I tried barek's answer, and the error is the same as with MSYS target - no sane c++ compiler. I next tried cmake-gui
, specifying compilers. Also, I made sure that MinGW/bin is in my path. Follows the error message:
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!
我怀疑问题出在某些非常愚蠢的地方,例如由于 MinGW 安装不当,CMAKE 无法更改目录.
I suspect the problem lies in somethign really stupid, like CMAKE not being able to change directories, due to impropper MinGW isntallation.
这里可以找到讨论,但我:
- 检查 MinGW/bin 是否在我的路径中
- 还在
cmake-gui
中手动指定了C和C++编译器路径 - 使用 SourceForge 的安装程序安装 MinGW 并选择复选框Alter PATH".
推荐答案
清理!删除所有以前的构建尝试,
CmakeFile.cache
等
在路径上有 MingW/bin
have MingW/bin on the path
在 opencv 目录中创建一个文件夹,名为 build_mingw,cd
在那里
make a folder within the opencv dir, called build_mingw, cd
there
cmake -G "MinGW Makefiles" -D CMAKE_CXX_COMPILER=mingw32-g++.exe -D CMAKE_MAKE_PROGRAM=mingw32-make.exe ..
# <-- 注意点结束
cmake -G "MinGW Makefiles" -D CMAKE_CXX_COMPILER=mingw32-g++.exe -D CMAKE_MAKE_PROGRAM=mingw32-make.exe ..
# <-- note the dots at the end
mingw32-make
mingw32-make install
这篇关于不确定如何为 MinGW 构建 OpenCV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!