4

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 not being in $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".
2
  • avoid msys, as it's messing with pathes, - just use a regular cmd.exe to run cmake, and build a regular MinGW Makefile. also have the mingw bins on the PATH, because it wants to run mingw32-make instead of make then Commented Jun 13, 2014 at 5:00
  • @berak, thanks for the tip. Do you have any advice how to cope with For MinGW make to work correctly sh.exe must NOT be in your path.? I tied renaming the file and then using cmd.exe, but there was no change. Commented Jun 13, 2014 at 6:37

2 Answers 2

10
  1. cleanup! delete all previous build attempts, CmakeFile.cache, etc.

  2. have MingW/bin on the path

  3. make a folder within the opencv dir, called build_mingw, cd there

  4. cmake -G "MinGW Makefiles" -D CMAKE_CXX_COMPILER=mingw32-g++.exe -D CMAKE_MAKE_PROGRAM=mingw32-make.exe .. # <-- note the dots at the end

  5. mingw32-make

  6. mingw32-make install

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks a lot. I was missing mingw32-make. I found this out by the help of cmake-gui and selected advanced option to list all cmake variables.
By the way, maybe an out of source build would be cleaner? For example ../build/mingw/.
yes, true. on the other hand, most people only keep the install dir and throw away the whole build folder (~2gb!)
I get to 62%, then this error appears: "modules\videoio\CMakeFiles\opencv_videoio.dir\build.make:126: recipe for target 'modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_dshow.cpp.obj' failed". What must I do?
0

I tried everthing mentioned here and CMAKE_MAKE_PROGRAM not found but nothing helped. Then restarted the computer and it works.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.