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

我使用gcc编译器和make工具链Mingw,我可以在一个简单的例子中成功运行。gcc.exemingw32-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
  • 为什么手动更改此变量没有解决问题?
4

1 回答 1

1

CMake 使用它检测到的值填充缓存文件,这些值基于CMakeLists.txt它所包含的内容以及它包含的任何文件以及-D提供给cmake.

在 Windows 上,CMake 将默认使用 Microsoft 的nmake工具。覆盖它的方法是将参数传递-G"MinGW Makefiles"cmake,或者在您使用 MSYS shell 的情况下-G"MSYS Makefiles"

但是有一个比make´ called Ninja (get it from https://ninja-build.org/) which you can use by passing -GNinja tocmake` 更快的构建工具。

注意:我看到您使用的是 Code::Blocks 附带的旧 MinGW。MinGW 有一个更新的后续版本,称为 MinGW-w64,它支持 Windows 32 位和 64 位。最近的独立版本可以从https://winlibs.com/下载,它还包括ninja.exe.

PS:如果您在遵循这些提示后在构建 nanomsg 源代码时遇到更多问题,请考虑传递-DNN_TESTS:BOOL=OFFcmake

于 2021-06-29T08:35:11.563 回答