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

axr492tv  于 2022-11-11  发布在  Windows
关注(0)|答案(1)|浏览(923)

尝试在Windows 7中构建nanomsg project时出现错误:

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编译器和Mingw工具链中的make,可以在一个简单的示例中成功运行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_PROGRAMnmake的值?
  • 为什么手动更改此变量不能解决问题?
kcwpcxri

kcwpcxri1#

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

相关问题