【问题标题】:cmake with git for windows, MinGW and makecmake 与 git for windows、MinGW 和 make
【发布时间】:2016-04-14 20:19:08
【问题描述】:

首先,我从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})

【问题讨论】:

  • 您是否告诉 CMake 您希望它在 make/gcc 模式而不是 VisualStudio 模式下工作?这样做有帮助吗?
  • 我该怎么做?当我运行 cmake gui 时,我可以进行配置,我尝试了“MSYS Makefiles”、“Unix Makefiles”,但结果是一样的。我应该尝试另一个吗?
  • 好吧,您没有使用 MSYS make 或 Unix make。您正在使用 gnuwin32 制作。

标签: cmake mingw


【解决方案1】:

好吧,对不起,

我必须重新启动计算机并在 CMake GUI 中选择“MinGW Makefiles”。单击配置,然后单击“生成”。

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

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 添加到系统路径。

【讨论】:

    【解决方案2】:

    您可以尝试设置manually the cxx path,请参阅链接中的 CMAKE_C_COMPILER,它会或多或少地告诉您链接:

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

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

    【讨论】:

      【解决方案3】:

      也许不是最好的答案,但让事情顺利进行。安装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:\

      关注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 将 Windows 特定的 SDK/代码推送到 github。我仍然会坚持使用 Git Bash 来处理 git。

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

      【讨论】:

        猜你喜欢
        • 2017-03-08
        • 2018-01-22
        • 2021-07-30
        • 2017-05-03
        • 1970-01-01
        • 2018-03-05
        • 2011-01-26
        • 1970-01-01
        • 2011-04-15
        相关资源
        最近更新 更多