EnableLanguage 之后未设置 CMAKE_C_COMPILER

Ana*_*ami 24 c c++ gcc cmake cmakelists-options

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

Run Code Online (Sandbox Code Playgroud)

小智 19

这些变量需要在命令行上传递,如下所示:

$ cmake -DCMAKE_CXX_COMPILER=/pathto/g++ -DCMAKE_C_COMPILER=/pathto/gcc /pathto/source
Run Code Online (Sandbox Code Playgroud)

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

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

project(mytest)
...
Run Code Online (Sandbox Code Playgroud)

-C <toolchain>或者用命令引入

# mygcc.cmake 
# toolchain file
set( CMAKE_CXX_COMPILER "/pathto/g++" )
set( CMAKE_C_COMPILER "/pathto/gcc" )
Run Code Online (Sandbox Code Playgroud)
set( CMAKE_CXX_COMPILER "/pathto/g++" )
set( CMAKE_C_COMPILER "/pathto/gcc" )

project(mytest)
...
Run Code Online (Sandbox Code Playgroud)

  • 路径/源是什么意思? (2认同)