CMAKE_C_COMPILER no establecido, después de EnableLanguage [duplicate]

2 minutos de lectura

Instalé CMake en Windows además del compilador gcc y g ++. Agregué las variables a la ruta pero sigo recibiendo el siguiente error. ¿Podrían ayudarme?

ingrese la descripción de la imagen aquí

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

  • Está intentando configurar el proyecto para el generador NMake, pero ejecutable nmake no es accesible en su máquina. Esto es lo que primer mensaje de error acerca de.

    – Tsyvarev

    29 de diciembre de 2021 a las 19:52

  • Gracias @Tsyvarev tienes razón. Definí el generador así. cmake -G "MinGW Makefiles" . y el primer error desapareció se lo agradezco

    – Anas Hosami

    30 de diciembre de 2021 a las 11:56

  • En mi caso fue por tratar de construir (cmake --build ..) antes de configurar (cmake ..). Cualquier comando de configuración posterior terminó con el error anterior. Eliminar todo en el directorio de compilación y volver a ejecutar cmake .. ¡arreglado!

    –Jonathan Levin

    3 de marzo de 2022 a las 14:28


Estas variables deben pasarse en la línea de comando como:

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

o configurar antes de la project() línea en CMakeLists.txt:

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

project(mytest)
...

o, alternativamente, traído con el -C <toolchain> comando como

# mygcc.cmake 
# toolchain file
set( CMAKE_CXX_COMPILER "/pathto/g++" )
set( CMAKE_C_COMPILER "/pathto/gcc" )
$ cmake -C /pathto/mygcc.cmake /pathto/source

  • es pathto un marcador de posición? Configuré mis compiladores así, ¿está bien? conjunto( CMAKE_CXX_COMPILER “C:/MinGW/bin/g++” ) conjunto( CMAKE_C_COMPILER “C:/MinGW/bin/gcc” )

    – axelrotter

    24 de mayo de 2022 a las 9:57


  • ¿Qué quieres decir con pathto/source ?

    – Gaurav Pandey

    28 oct 2022 a las 14:48

¿Ha sido útil esta solución?