-->

cmake with git for windows, MinGW and make

2020-07-17 15:36发布

问题:

Firstly, I have installed MinGW from https://sourceforge.net/projects/mingw/files/ and the mingw32-gcc-g++ and mingw32-gcc-objs with it. I have added C:\MinGW\bin to my path.

Secondly, I have installed Git for windows (not really important, the result is the same on cmd.exe).

Thirdly, I have installed the complete package "make" with http://gnuwin32.sourceforge.net/packages/make.htm

After that, I have installed cmake 3.5.1 with the .msi.

But when I run cmake ../src the result is :

-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:5 (project):
No CMAKE_C_COMPILER could be found.



CMake Error at CMakeLists.txt:5 (project):
  No CMAKE_CXX_COMPILER could be found.

-- Configuring incomplete, errors occurred!
See also "C:/Users/pauka/Dropbox/ETUDE/SRI/S8/STA_Stage/sources/tests/bin/CMakeFiles/CMakeOutput.log".
See also "C:/Users/pauka/Dropbox/ETUDE/SRI/S8/STA_Stage/sources/tests/bin/CMakeFiles/CMakeError.log".

So cmake can't find gcc or g++. But when I run gcc -version, the output is good... What should I configure for cmake ?

My CMakeLists.txt is :

# Ajustez en fonction de votre version de CMake
cmake_minimum_required (VERSION 2.8)

# Nom du projet
project (main)

find_package (OpenCV REQUIRED)

# Exécutable "main", compilé à partir du fichier main.cpp
add_executable (tracking_color tracking_color.cpp)
add_executable (feuille feuille.cpp)
add_executable (detect_circles detect_circles.cpp)
add_executable (segmentation segmentation.cpp)
add_executable (watershed_perso watershed_perso.cpp)
add_executable (main main.cpp utils.h)
add_executable (info_coins info_coins.cpp)

# main sera linké avec les bibliothèques d'OpenCV
target_link_libraries (tracking_color ${OpenCV_LIBS})
target_link_libraries (feuille ${OpenCV_LIBS})
target_link_libraries (detect_circles ${OpenCV_LIBS})
target_link_libraries (segmentation ${OpenCV_LIBS})
target_link_libraries (watershed_perso ${OpenCV_LIBS})
target_link_libraries (info_coins ${OpenCV_LIBS})
target_link_libraries (main ${OpenCV_LIBS})

回答1:

Ok, shame on me,

I had to restart my computer and select "MinGW Makefiles" in the CMake GUI. Click configure, and after that "Generate".

Next, you must not use "Git for windows" because there is "sh.exe" and it's a cmake bug.

PS: to use OpenCV, you must compile it :

cd C:\opencv
mkdir my_build
cd my_build
cmake -G "MinGW Makefiles" ../sources
mingw32-make # took 2 hours on my computer

and next add, C:\opencv\my_build and C:\opencv\my_build\bin to the system path.



回答2:

You can try setting manually the cxx path, see CMAKE_C_COMPILER from link which tells you more or less link this:

CXX=C:\path\to\g++ cmake ..

But, I would recommend you to see why cmake doesn't recognize your cxx compiler. I would double check your environment paths.



回答3:

Maybe not the best answer but get things going. Install Bash On Ubuntu On Windows and install cmake and make using sudo apt-get install cmake and sudo apt-get install build-essential if you don't already have them installed. However, Bash On Ubuntu On Windows only comes with Windows 10 and for accessing a specific drive you should use /mnt/c instead of C:\

Follow this official tutorial to install Bash On Ubuntu On Windows.

mona@DESKTOP-0JQ770H:/mnt/c$ cmake -version
cmake version 2.8.12.2
mona@DESKTOP-0JQ770H:/mnt/c$ make -version
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for x86_64-pc-linux-gnu

Additionally, of course you can install git in Bash On Ubuntu On Windows

sudo apt-get install git
mona@DESKTOP-0JQ770H:/mnt/c$ git --version
git version 1.9.1

though I don't suggest using a Linux-based git for pushing to github for a Windows specific SDK/code. I would still stick to Git Bash for dealing with git.

*I used to use CMAKE GUI for dealing with CMake in Windows 10 and then port my stuff to Visual Studio. That is also a neat solution depending on your codebase.



标签: cmake mingw