CMake failing gcc compiler checks

CMake for some reason has stopped working recently. I’m trying to compile DDNet because I like to patch it however am failing. The same error occurs on every project using c(pp) with this error.

-- The C compiler identification is GNU 13.1.1
-- The CXX compiler identification is GNU 13.1.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc - broken
CMake Error at /usr/share/cmake/Modules/CMakeTestCCompiler.cmake:67 (message):
  The C compiler
    "/usr/bin/cc"
  is not able to compile a simple test program.
  It fails with the following output:
    Change Dir: /home/solly/Temp/cmaketest/build/CMakeFiles/CMakeScratch/TryCompile-IOmZ6M
    Run Build Command(s):/usr/bin/cmake -E env VERBOSE=1 /usr/bin/make -f Makefile cmTC_10cbb/fast && /usr/bin/make  -f CMakeFiles/cmTC_10cbb.dir/build.make CMakeFiles/cmTC_10cbb.dir/build
    make[1]: Entering directory '/home/solly/Temp/cmaketest/build/CMakeFiles/CMakeScratch/TryCompile-IOmZ6M'
    /bin/sh: line 1: 2: command not found
    /bin/sh: line 1: 255: command not found
    /bin/sh: line 1: 221: command not found
    /bin/sh: line 1: 255m: command not found
    make[1]: *** [CMakeFiles/cmTC_10cbb.dir/build.make:77: CMakeFiles/cmTC_10cbb.dir/testCCompiler.c.o] Error 127
    make[1]: Leaving directory '/home/solly/Temp/cmaketest/build/CMakeFiles/CMakeScratch/TryCompile-IOmZ6M'
    make: *** [Makefile:127: cmTC_10cbb/fast] Error 2
  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:7 (project)
-- Configuring incomplete, errors occurred!

(cmake-examples/01-basic/A-hello-cmake at master · ttroy50/cmake-examples · GitHub)
Im on Arch Linux 6.3.3 x86_64 fully updated as of 7 Jun 2023
Cmake ver: 3.26.4
Make ver: GNU 4.4.1
GCC ver: 13.1.1
I can use c, c++ & Make on other projects & they work fine.
Subverting the issue by disabling/bypassing the compiler checks works for simple cases like these, but for DDNet just leads to more and more errors which I have spent a good time disabling all the checks for, but they never end…
I have no idea why this is happening, please help ):

Can you get the contents of that TryCompile-IOmZ6M file? Or otherwise find where these are coming from? It almost looks like ANSI color codes being output into the files. Do you have colors forced on for any relevant tool?

Nope, they are gone.
/bin/sh: line 1: 2: command not found
/bin/sh: line 1: 255: command not found
/bin/sh: line 1: 221: command not found
/bin/sh: line 1: 255m: command not found
suggets that it tried to execute ansii escape codes from some log output, i dont know how the heck that happens

You can use --debug-trycompile to keep the files around.

So it calls make -f CMakeFiles/CMakeScratch/TryCompile-H8hzdo/
which calls make -f CMakeFiles/CMakeScratch/TryCompile-H8hzdo/CMakeFiles/Makefile2
which calls make -f CMakeFiles/CMakeScratch/cmTC_69db8.dir/Makefile (the H8hzdo directory does nothing)
which calls make -f CMakeFiles/CMakeScratch/cmTC_69db8.dir/CMakeFiles/Makefile2
which calls make -f CMakeFiles/cmTC_dbef9.dir/build.make CMakeFiles/cmTC_dbef9.dir/build (i cba to find the absolute path of these) (the m79UQt directory does nothing)
which finnally calls this

$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --progress-dir=/home/solly/Temp/cmaketest/build/CMakeFiles/CMakeScratch/TryCompile-m79UQt/CMakeFiles --progress-num=$(CMAKE_PROGRESS_2) "Linking C executable cmTC_dbef9"
@$(CMAKE_COMMAND) -E cmake_link_script CMakeFiles/cmTC_dbef9.dir/link.txt --verbose=$(VERBOSE)

which is also known as

/usr/bin/cmake -E cmake_echo_color --switch=[38;2;255;221;255m --progress-dir=/home/solly/Temp/cmaketest/build/CMakeFiles/CMakeScratch/TryCompile-m79UQt/CMakeFiles --progress-num=2 "Linking C executable cmTC_dbef9"
echo /usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_dbef9.dir/link.txt --verbose=1
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_dbef9.dir/link.txt --verbose=1

(found the error… forgot to stick it in ")
where the last command does what i assume is meant of it

Using built-in specs.
COLLECT_GCC=/usr/bin/cc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/13.1.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --enable-languages=ada,c,c++,d,fortran,go,lto,objc,obj-c++ --enable-bootstrap --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --with-build-config=bootstrap-lto --with-linker-hash-style=gnu --with-system-zlib --enable-__cxa_atexit --enable-cet=auto --enable-checking=release --enable-clocale=gnu --enable-default-pie --enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object --enable-libstdcxx-backtrace --enable-link-serialization=1 --enable-linker-build-id --enable-lto --enable-multilib --enable-plugin --enable-shared --enable-threads=posix --disable-libssp --disable-libstdcxx-pch --disable-werror
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.1.1 20230429 (GCC)
COMPILER_PATH=/usr/lib/gcc/x86_64-pc-linux-gnu/13.1.1/:/usr/lib/gcc/x86_64-pc-linux-gnu/13.1.1/:/usr/lib/gcc/x86_64-pc-linux-gnu/:/usr/lib/gcc/x86_64-pc-linux-gnu/13.1.1/:/usr/lib/gcc/x86_64-pc-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-pc-linux-gnu/13.1.1/:/usr/lib/gcc/x86_64-pc-linux-gnu/13.1.1/../../../../lib/:/lib/../lib/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-pc-linux-gnu/13.1.1/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-o' 'cmTC_dbef9' '-mtune=generic' '-march=x86-64' '-dumpdir' 'cmTC_dbef9.'
 /usr/lib/gcc/x86_64-pc-linux-gnu/13.1.1/collect2 -plugin /usr/lib/gcc/x86_64-pc-linux-gnu/13.1.1/liblto_plugin.so -plugin-opt=/usr/lib/gcc/x86_64-pc-linux-gnu/13.1.1/lto-wrapper -plugin-opt=-fresolution=/tmp/ccflhfZJ.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s --build-id --eh-frame-hdr --hash-style=gnu -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -pie -o cmTC_dbef9 /usr/lib/gcc/x86_64-pc-linux-gnu/13.1.1/../../../../lib/Scrt1.o /usr/lib/gcc/x86_64-pc-linux-gnu/13.1.1/../../../../lib/crti.o /usr/lib/gcc/x86_64-pc-linux-gnu/13.1.1/crtbeginS.o -L/usr/lib/gcc/x86_64-pc-linux-gnu/13.1.1 -L/usr/lib/gcc/x86_64-pc-linux-gnu/13.1.1/../../../../lib -L/lib/../lib -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-pc-linux-gnu/13.1.1/../../.. CMakeFiles/cmTC_dbef9.dir/CMakeCCompilerABI.c.o -lgcc --push-state --as-needed -lgcc_s --pop-state -lc -lgcc --push-state --as-needed -lgcc_s --pop-state /usr/lib/gcc/x86_64-pc-linux-gnu/13.1.1/crtendS.o /usr/lib/gcc/x86_64-pc-linux-gnu/13.1.1/../../../../lib/crtn.o
COLLECT_GCC_OPTIONS='-v' '-o' 'cmTC_dbef9' '-mtune=generic' '-march=x86-64' '-dumpdir' 'cmTC_dbef9.'

I must say, after doing this, I do not like cmake more than I did before

Settings NO_COLOR and COLOR_DEBUG_NO_COLOR (in an attempt to remove color and thus this issue) does not work (Allow users to disable color output via CMake option · Issue #20 · roboticslab-uc3m/color-debug · GitHub)

So it looks like CMake is using the COLOR variable. Makefiles will pick this up from the environment as well; do you have COLOR set in your environment?

The Makefile generators use a complicated setup in order to do some of the use cases they handle. Someday, we’ll get to rewrite it to be more like the Ninja generator which has a global view of the build graph (instead of the extra per-directory UI layer that gets put on top for the existing one). Generally, the Ninja generator is recommended these days.

As for the quotes, I’ll get an MR up. Thanks for the logs showing the problem.

1 Like

You are completley right, i had the COLOR variable set. Thanks!

Fix to at least make things not be so obtuse (having it set probably still interferes with things though): https://gitlab.kitware.com/cmake/cmake/-/merge_requests/8548