cmake 与 git for windows, MinGW 和 make

cmake with git for windows, MinGW and make

首先,我从 https://sourceforge.net/projects/mingw/files/ 安装了 MinGW 以及 mingw32-gcc-g++ 和 mingw32-gcc-objs。我已将 C:\MinGW\bin 添加到我的路径中。

其次,我为windows安装了Git(不是很重要,结果在cmd.exe上是一样的)。

第三,我已经安装了完整的软件包 "make" 和 http://gnuwin32.sourceforge.net/packages/make.htm

之后,我安装了带有 .msi 的 cmake 3.5.1。

但是当我 运行 cmake ../src 结果是:

-- 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".

所以cmake找不到gcc或g++。但是当我 运行 gcc -version 时,输出很好...我应该为 cmake 配置什么?

我的 CMakeLists.txt 是:

# 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})

您可以尝试设置 manually the cxx path,请参阅 link 中的 CMAKE_C_COMPILER,它或多或少告诉您 link 这个:

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

但是,我建议您看看为什么 cmake 无法识别您的 cxx 编译器。我会仔细检查您的环境路径。

好吧,真丢人,

我不得不在 CMake GUI 中重新启动计算机和 select "MinGW Makefiles"。点击configure,然后"Generate".

接下来,你不能使用"Git for windows",因为有"sh.exe",这是一个cmake bug。

PS: 要使用OpenCV,你必须编译它:

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

然后添加C:\opencv\my_build和C:\opencv\my_build\bin到系统路径。

也许不是最好的答案,但让事情继续下去。安装 Bash On Ubuntu On Windows 并安装 cmake 并使用 sudo apt-get install cmakesudo apt-get install build-essential 如果您还没有安装它们。但是,Bash On Ubuntu On Windows 仅随 Windows 10 提供,要访问特定驱动器,您应该使用 /mnt/c 而不是 C:\

按照 this official tutorial 安装 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

此外,当然你可以在Bash On Ubuntu On Windows

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

尽管我不建议使用基于 Linux 的 git 推送到 git 集线器以获得 Windows 特定 SDK/code。我仍然会坚持 Git Bash 来处理 git.

*我曾经在 Windows 10 中使用 CMAKE GUI 来处理 CMake,然后将我的东西移植到 Visual Studio。根据您的代码库,这也是一个巧妙的解决方案。