Skip to content

MSYS/MinGW Makfiles: Hardcoded gcc/g++ does not exist on MINGW/CLANG

cmake_minimum_required(VERSION 3.16)
project(test CXX)
add_executable(main main.cpp)

The clang++ compiler is in PATH:

$ whereis clang++
clang++: /clang64/bin/clang++.exe

"MSYS Makefiles"

$ cmake -B build/msys -G"MSYS Makefiles"
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:2 (project):
  The CMAKE_CXX_COMPILER:

    g++.exe

  is not a full path and was not found in the PATH.

  Tell CMake where to find the compiler by setting either the environment
  variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
  to the compiler, or to the compiler name if it is in the PATH.


-- Configuring incomplete, errors occurred!
See also "D:/dev/Bugs/cmake_code/build/msys/CMakeFiles/CMakeOutput.log".
See also "D:/dev/Bugs/cmake_code/build/msys/CMakeFiles/CMakeError.log".

"MinGW Makefiles":

$ cmake -B build/mingw -G"MinGW Makefiles"
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:2 (project):
  The CMAKE_CXX_COMPILER:

    g++.exe

  is not a full path and was not found in the PATH.

  Tell CMake where to find the compiler by setting either the environment
  variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
  to the compiler, or to the compiler name if it is in the PATH.


-- Configuring incomplete, errors occurred!
See also "D:/dev/Bugs/cmake_code/build/mingw/CMakeFiles/CMakeOutput.log".
See also "D:/dev/Bugs/cmake_code/build/mingw/CMakeFiles/CMakeError.log".

That's because the c/c++ compiler executable names are hardcoded for these generators:

https://gitlab.kitware.com/cmake/cmake/-/blob/v3.23.1/Source/cmGlobalMSYSMakefileGenerator.cxx#L54

https://gitlab.kitware.com/cmake/cmake/-/blob/v3.23.1/Source/cmGlobalMinGWMakefileGenerator.cxx#L32

I think these lines should be removed to let cmake searches for C/C++ compiler like any other generator (skip https://gitlab.kitware.com/cmake/cmake/-/blob/v3.23.1/Modules/CMakeDetermineCXXCompiler.cmake#L53 and https://gitlab.kitware.com/cmake/cmake/-/blob/v3.23.1/Modules/CMakeDetermineCCompiler.cmake#L54)

Edited by Brad King
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information