【问题标题】:running makefile created by cmake with gcc compiler使用 gcc 编译器运行 cmake 创建的 makefile
【发布时间】:2015-07-30 11:49:34
【问题描述】:

我正在尝试使用 cmake。假设我的源目录中有一个 HelloWorld.c 文件和一个 CMakeList.txt,其中包含以下内容:

CMAKE_MINIMUM_REQUIRED(VERSION 2.6)

    PROJECT( HelloWorld )

    ADD_EXECUTABLE( helloworld HelloWorld.c )

当我在此目录中调用 cmake(使用 minGW 生成器)时,一切正常,生成的构建树还包含一个 "Makefile" 。我现在的问题是:这个生成的 makefile 也可以用作通常的手动创建的 makefile。例如,当我在命令 promtp 中键入“make”时,项目应该构建。但我什么也没看到,只有:

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

这个输出。这里有什么不明白的地方?

我正在使用 cmake GUI 生成构建树并获得以下输出:

The C compiler identification is GNU 4.8.1
The CXX compiler identification is GNU 4.8.1
Check for working C compiler: C:/MinGW/bin/gcc.exe
Check for working C compiler: C:/MinGW/bin/gcc.exe -- works
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Detecting C compile features
Detecting C compile features - done
Check for working CXX compiler: C:/MinGW/bin/g++.exe
Check for working CXX compiler: C:/MinGW/bin/g++.exe -- works
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Detecting CXX compile features
Detecting CXX compile features - done
Configuring done
Generating done

那么,这意味着,在我的构建目录中,所有与 gcc 编译器相关的东西都是正确的吗? 但是,我也无法理解,当我从 HelloWorld.c 和 CMakeList.Txt 所在的源目录运行 cmake 时,我得到了这个输出:

C:\testworkspace\cmake>cmake C:\testworkspace\cmake
-- Building for: Visual Studio 10 2010
-- The C compiler identification is MSVC 16.0.40219.1
-- The CXX compiler identification is MSVC 16.0.40219.1
-- Check for working C compiler using: Visual Studio 10 2010
-- Check for working C compiler using: Visual Studio 10 2010 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working CXX compiler using: Visual Studio 10 2010
-- Check for working CXX compiler using: Visual Studio 10 2010 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Detecting CXX compile features
-- Detecting CXX compile features - failed
-- Configuring done
-- Generating done
-- Build files have been written to: C:/testworkspace/cmake

C:\testworkspace\cmake>

为什么 cmake 采用 Visual Studio 编译器?在 GUI 中配置了 MinGW 编译器!?

【问题讨论】:

  • 你在Makefile所在的同一个文件夹中吗?
  • 是的,我正在从它的文件夹中运行 make :S
  • 你用的是什么编译器?您谈到了 minGW,但您的品牌似乎链接了 microsoft nmake
  • make helloworld 怎么样?或者make 并按下制表键?
  • 我正在使用 gcc 编译器。此外,当我查看 CMakeCach.Txt 文件时,gcc 被指定为编译器。但奇怪的是,当我查看生成的 makefile 时,没有任何关于 gcc 编译器的内容.. hmm

标签: cmake gnu-make


【解决方案1】:

问题解决了。 因此,当我使用 Cmake GUI 配置构建树时,出现以下错误:

CMake Error at C:/Program Files (x86)/CMake/share/cmake-    3.3/Modules/CMakeMinGWFindMake.cmake:22 (message):
  sh.exe was found in your PATH, here:

  C:/MinGW/msys/1.0/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:6 (PROJECT)

当我从 Cmake GUI 中删除 C:/MinGW/msys/1.0/bin/sh.exe 路径时,它可以工作并使用 MinGW 生成器生成构建树。

因此,如果我想通过源目录中的命令行执行此过程,我必须调用 cmake -G "MSYS Makefiles" 而不是 -G "MinGW Makefiles"!此处解释了此行为:http://www.cmake.org/Wiki/CMake_MinGW_Compiler_Issues

现在我只需从生成构建树的同一目录运行 "make" 即可。

【讨论】:

猜你喜欢
  • 2013-02-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-26
  • 1970-01-01
  • 2019-01-08
  • 2014-11-05
  • 1970-01-01
相关资源
最近更新 更多