CMake错误:在Windows上执行make失败

8

当我尝试在Windows 7上构建nanomsg项目时,我遇到了错误:

cmake ..
-- Building for: NMake Makefiles
-- The C compiler identification is GNU 4.7.1
-- Check for working C compiler: C:/Program Files (x86)/CodeBlocks/MinGW/bin/gcc.exe
CMake Error: Generator: execution of make failed. Make command was: "nmake" "/NOLOGO" "cmTC_5d837\fast"
-- Check for working C compiler: C:/Program Files (x86)/CodeBlocks/MinGW/bin/gcc.exe -- broken
CMake Error at C:/Program Files (x86)/cmake-3.9.4-win64-x64/share/cmake-3.9/Modules/CMakeTestCCompiler.cmake:51 (message):
The C compiler "C:/Program Files (x86)/CodeBlocks/MinGW/bin/gcc.exe" is not
able to compile a simple test program.

It fails with the following output:

Change Dir: C:/Users/User/Documents/Internal/nanomsg-master/build/CMakeFiles/CMakeTmp



Run Build Command:"nmake" "/NOLOGO" "cmTC_5d837\fast"



Generator: execution of make failed.  Make command was: "nmake" "/NOLOGO"
"cmTC_5d837\fast"





CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:29 (project)


-- Configuring incomplete, errors occurred!
See also "C:/Users/User/Documents/Internal/nanomsg-master/build/CMakeFiles/CMakeOutput.log".
See also "C:/Users/User/Documents/Internal/nanomsg-master/build/CMakeFiles/CMakeError.log".

我使用来自Mingw工具链的gcc编译器和make,并且可以在简单示例中成功运行gcc.exe和mingw32-make.exe。
在文件CMakeCache.txt中,缓存变量设置如下:
//C compiler
CMAKE_C_COMPILER:FILEPATH=C:/Program Files (x86)/CodeBlocks/MinGW/bin/gcc.exe

//Program used to build from makefiles.
CMAKE_MAKE_PROGRAM:STRING=nmake

我认为问题出在 CMAKE_MAKE_PROGRAM 变量上,它应该取值为 C:/Program Files (x86)/CodeBlocks/MinGW/bin/mingw32-make.exe,但是我不知道它为什么会取值 nmake

即使我手动替换它,仍然会出现相同的问题。

我的问题:

  • CMake 如何填充缓存变量?
  • 为什么 CMAKE_MAKE_PROGRAM 取值为 nmake
  • 为什么手动更改此变量没有解决问题?

3
可能是CMakeLists.txt:30 (project)错误的重复内容:找不到任何CMAKE_C_COMPILER。您需要在CMake命令行中指定一个生成器,例如-G“MinGW Makefiles”,并且 - 根据您安装了多少编译器 - 还需要指定编译器的完整路径。 - Florian
@Florian,感谢您的反馈,好的,问题解决了:)。当我更改生成器时发生了什么?CMake是否有内部脚本来搜索C编译器和make程序,然后更新缓存变量,因为现在我可以看到CMakeCache.txt中的变量具有良好的值。 - Mouin
1
@Mouin - nmake 是微软的 make 工具。您可以从 Visual C++ 2015 Build Tools 获取它的副本。您不再需要下载 Visual Studio 或处理过期试用版。Build Tools 是 Visual Studio 工具的子集,其中包括编译器、链接器、nmake 和一些其他 Windows 必备工具。 - jww
1个回答

6
CMake会根据 CMakeLists.txt 中的内容以及与其组合使用的任何文件以及提供给cmake的任何-D参数检测到的值,填充缓存文件。在Windows上,CMake默认使用Microsoft的nmake工具。覆盖此设置的方式是将参数-G"MinGW Makefiles"传递给cmake,或者在使用MSYS shell的情况下是-G"MSYS Makefiles"。但是,还有一种比make更快的构建工具叫做Ninja(从https://ninja-build.org/获取),您可以通过向cmake传递-GNinja来使用它。注意:我看到你正在使用Code::Blocks附带的旧MinGW。MinGW的一个更现代的后继版本叫做MinGW-w64,支持Windows 32位和64位。可以从https://winlibs.com/下载最新的独立构建,并且其中还包括ninja.exe。附言:如果按照这些提示后仍然遇到更多构建nanomsg源代码的问题,请考虑向cmake传递-DNN_TESTS:BOOL=OFF

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