使用git for windows、MinGW和make的cmake

6
首先,我从https://sourceforge.net/projects/mingw/files/下载并安装了MinGW,同时也安装了mingw32-gcc-g++和mingw32-gcc-objs。我将C:\MinGW\bin添加到了环境变量中。
其次,我安装了Windows版的Git(这不是非常重要,因为在cmd.exe中结果是相同的)。
第三步,我使用http://gnuwin32.sourceforge.net/packages/make.htm下载并安装了完整的“make”软件包。
之后,我通过.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})

1
你告诉了CMake你想让它在“make” / “gcc”模式下工作而不是VisualStudio模式吗? 这样做有帮助吗? - Etan Reisner
我该怎么做?当我运行cmake gui时,我可以进行配置,我尝试了“MSYS Makefiles”、“Unix Makefiles”,但结果都一样。我应该再尝试另一个吗? - onda47
1
你没有使用MSYS make或Unix make,而是使用gnuwin32 make。 - Ross Ridge
3个回答

4

好的,我的错。

我必须重新启动电脑,在CMake GUI中选择"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_buildC:\opencv\my_build\bin 添加到系统路径中。


因为你没有在 make 命令中使用并行构建标志“-j”,所以花费了两个小时 :') - Chnossos

0

您可以尝试手动设置 cxx路径, 参见链接中的CMAKE_C_COMPILER,它会告诉您类似于以下内容:

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

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


0
也许不是最好的答案,但可以让事情开始进行。安装 Bash On Ubuntu On Windows 并使用 sudo apt-get install cmakesudo apt-get install build-essential 安装 cmake 和 make(如果你还没有安装它们的话)。然而,Bash On Ubuntu On Windows 只适用于 Windows 10,如果要访问特定的驱动器,应该使用 /mnt/c 而不是 C:\
请参考官方教程来安装 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将Windows特定的SDK/代码推送到github。但我仍然会坚持使用Git Bash来处理git。

*我曾经使用CMAKE GUI来处理Windows 10中的CMake,然后将我的东西移植到Visual Studio。这也是一个不错的解决方案,具体取决于您的代码库。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接