2

除了 gcc 和 g++ 编译器之外,我还在 Windows 上安装了 CMake 我将变量添加到路径中,但仍然出现以下错误,请您帮忙。

在此处输入图像描述

-- Building for: NMake Makefiles
CMake Error at CMakeLists.txt:6 (project):
  Running

   'nmake' '-?'

  failed with:

   The system cannot find the file specified


CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
See also "C:/Users/DEANHOS/Desktop/peer/cmake tutorial/codeAndTech/sample/CMakeFiles/CMakeOutput.log".

4

1 回答 1

1

这些变量需要在命令行上传递为:

$ cmake -DCMAKE_CXX_COMPILER=/pathto/g++ -DCMAKE_C_COMPILER=/pathto/gcc /pathto/source

project()或在 CMakeLists.txt中的行前设置:

set( CMAKE_CXX_COMPILER "/pathto/g++" )
set( CMAKE_C_COMPILER "/pathto/gcc" )

project(mytest)
...

或者使用-C <toolchain>命令作为

# mygcc.cmake 
# toolchain file
set( CMAKE_CXX_COMPILER "/pathto/g++" )
set( CMAKE_C_COMPILER "/pathto/gcc" )
$ cmake -C /pathto/mygcc.cmake /pathto/source
于 2021-12-29T19:38:53.043 回答