不知道如何为MinGW构建OpenCV [英] Not sure how to build OpenCV for MinGW
问题描述
TL; DR;
我试图为MinGW构建OpenCV。 cmake
不断抱怨没有理智的CXX编译器,虽然我可以编译示例代码与g ++。
$ b
长版本
我尝试为MinGW ,但此操作无效。
我试图编译MinGW,但是失败,关于sh.exe在他的路径的一些错误。我很困惑,因为重命名文件系统上的目标文件没有解决问题。
E:\work\opencv \mybuild> cmake -GMinGW Makefiles../sources
CMake错误在C:/ Program Files(x86)/ CMake 2.8 / share / cmake-2.8 / Modules / CMakeMin
GWFindMake.cmake:22 ):
sh.exe在您的PATH中找到,其中:
C:/ Users / desuna / AppData / Local / GitHub / PortableGit_054f2e797ebafd44a30203088cd3d
58663c627ef / bin /sh.exe
对于MinGW使正常工作sh.exe不能在您的路径中。
从在PATH中没有sh.exe的shell运行cmake。
如果要使用UNIX shell,请使用MSYS Makefiles。
调用堆栈(最近调用):
CMakeLists.txt:56(project)
CMake错误:CMake无法找到构建程序对应于MinGW Ma
kefiles。未设置CMAKE_MAKE_PROGRAM。你可能需要选择一个不同的
nt构建工具。
CMake错误:CMake无法找到对应于MinGW Ma
kefiles的构建程序。未设置CMAKE_MAKE_PROGRAM。你可能需要选择一个不同的
nt构建工具。
CMake错误:需要内部CMake变量未设置,cmake可能不是
正确构建。
缺少变量是:
CMAKE_CXX_COMPILER_ENV_VAR
CMake错误:需要内部CMake变量未设置,cmake可能不是
正确构建。
缺少变量是:
CMAKE_CXX_COMPILER
CMake错误:找不到cmake模块文件:E:/ work / opencv / mybuild / CMakeFiles
/2.8.12.2/CMakeCXXCompiler.cmake
CMake错误:需要内部CMake变量未设置错误,cmake可能不是
正确构建。
缺少变量是:
CMAKE_C_COMPILER_ENV_VAR
CMake错误:需要内部CMake变量未设置,cmake可能不是
正确构建。
缺少变量是:
CMAKE_C_COMPILER
CMake错误:找不到cmake模块文件:E:/ work / opencv / mybuild / CMakeFiles
/2.8.12.2/CMakeCCompiler.cmake
CMake错误:CMAKE_CXX_COMPILER未设置,在EnableLanguage后
CMake错误:CMAKE_C_COMPILER未设置,在EnableLanguage后
- 配置不完整,发生错误!
我后来被通知,MSYS的makefile没有这个要求。现在有一个关于C ++编译器的错误。但是,正确识别了C ++编译器。此外,我试着编译一个虚拟的test.cxx程序,它工作。
E:\work\opencv\mybuild> ; cmake -GMSYS Makefiles../sources
- CXX编译器标识是GNU 4.8.1
- C编译器标识是GNU 4.8.1
- 检查工作CXX编译器:C:/ MinGW / bin / g ++。exe
- 检查工作CXX编译器:C:/ MinGW / bin / g ++。exe - broken
CMake错误在C:/ Program Files (x86)/ CMake 2.8 / share / cmake-2.8 / Modules / CMakeTes
tCXXCompiler.cmake:54(message):
C ++编译器C:/ MinGW / bin / g ++。exe能够编译一个简单的
测试程序。
它失败,输出如下:
更改目录:E:/ work / opencv / mybuild / CMakeFiles / CMakeTmp
错误日志是:
确定CXX编译器工作失败,输出如下:
更改Dir:E:/ work / opencv / mybuild / CMakeFiles / CMakeTmp
运行构建命令:C:/ PROGRA〜2 / GnuWin32 / make.execmTryCompileExec1507552824 / fast
C:/PROGRA~2/GnuWin32/bin/make.exe -f CMakeFiles / cmTryCompileExec1507552824.dir / build.make CMakeFiles / cmTryCompileExec1507552824.dir / build
make.exe [1]:进入目录`E:/ work / opencv / mybuild / CMakeFiles / CMakeTmp'
/ C / Program Files(x86)/ CMake 2.8 / bin / exe-E cmake_progress_report / E / work / opencv / mybuild / CMakeFiles / CMakeTmp / CMakeFiles 1
构建CXX对象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,...)失败。
make(e = 2):系统找不到指定的文件。
make.exe [1]:*** [CMakeFiles / cmTryCompileExec1507552824.dir / testCXXCompiler.cxx.obj]错误2
make.exe [1 ]:离开目录`E:/ work / opencv / mybuild / CMakeFiles / CMakeTmp'
make.exe:*** [cmTryCompileExec1507552824 / fast]错误2
我的目标是在Windows 7下针对C ++中的一个小应用程序进行一步式构建,该程序链接到onecv_core,opencv_highgui等等。为此,似乎我需要从源代码构建OpenCV与gcc下mingw。请指出正确的方法。
编辑:
我试过 barek 的答案,错误与MSYS target相同 - 没有理智的c ++编译器。我接下来尝试了 cmake-gui
,指定了编译器。此外,我确保MinGW / bin在我的路径。按照错误消息:
CMake错误:CMake无法找到与MinGW Makefiles对应的构建程序。未设置CMAKE_MAKE_PROGRAM。您可能需要选择一个不同的构建工具。
CMake错误:CMake无法找到对应于MinGW Makefiles的构建程序。未设置CMAKE_MAKE_PROGRAM。您可能需要选择一个不同的构建工具。
CMake错误:需要内部CMake变量未设置,需要CMake可能无法正确构建。
缺少变量是:
CMAKE_CXX_COMPILER_ENV_VAR
CMake错误:找不到cmake模块文件:E:/work/opencv/mybuild/CMakeFiles/2.8.12.2/CMakeCXXCompiler.cmake
CMake错误:需要内部CMake变量未设置,需要CMake可能无法正确构建。
缺少变量是:
CMAKE_C_COMPILER_ENV_VAR
CMake错误:找不到cmake模块文件:E:/work/opencv/mybuild/CMakeFiles/2.8.12.2/CMakeCCompiler.cmake
配置不完整,错误发生!
我怀疑问题在于somethign真的很愚蠢,像CMAKE不能改变目录,
这里可以找到讨论,但我:
- 检查MinGW / bin是否在我的路径
- 在
cmake-gui
中手动指定C和C ++编译器路径 - 使用安装程序安装MinGW来自SourceForge并选择了勾选框Alter PATH。
-
清理!删除所有以前的构建尝试,
CmakeFile.cache
等。 -
-
cmake -GMinGW Makefiles-D CMAKE_CXX_COMPILER = mingw32-g ++。exe -D CMAKE_MAKE_PROGRAM = mingw32-make.exe .. $ c $
-
mingw32-make
-
mingw32-make install
TL;DR;
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.
Long version
I tried finding a binary for MinGW, but this didn't work.
I tried compiling for MinGW, but that fails with some error about sh.exe being in he path. I am puzzled, as renaming the target file on the filesystem did not resolve the issue.
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!
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:\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
The error log is:
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
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.
EDIT:
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!
I suspect the problem lies in somethign really stupid, like CMAKE not being able to change directories, due to impropper MinGW isntallation.
Here a discussion can be found, but I:
- Checked that MinGW/bin is in my path
- Also specified the C and C++ compiler paths manually in
cmake-gui
- Installed MinGW with the installer from SourceForge and selected the tickbox "Alter PATH".
cleanup! delete all previous build attempts,
CmakeFile.cache
, etc.have MingW/bin on the path
make a folder within the opencv dir, called build_mingw,
cd
therecmake -G "MinGW Makefiles" -D CMAKE_CXX_COMPILER=mingw32-g++.exe -D CMAKE_MAKE_PROGRAM=mingw32-make.exe ..
# <-- note the dots at the endmingw32-make
mingw32-make install
这篇关于不知道如何为MinGW构建OpenCV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!