CMakeTestCXXCompiler fail on GCC 9.2 under Ubuntu 18.04

I use wsl with Ubuntu 18.04. I upgraded my GCC from version 7 to version 9.2 and now I can no longer compile my project. I have this error message. I also upgraded my cmake version from 3.10 to 3.16.4

 cmake -G"Unix Makefiles" ./.. && make && ./tests/unit_tests/UnitTests.out
-- The CXX compiler identification is unknown
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- broken
CMake Error at /home/matthieu/cmake-3.16.4-Linux-x86_64/share/cmake-3.16/Modules/CMakeTestCXXCompiler.cmake:53 (message):
  The C++ compiler

    "/usr/bin/c++"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /home/matthieu/StraightforwardNeuralNetwork/build/CMakeFiles/CMakeTmp

    Run Build Command(s):/usr/bin/make cmTC_990de/fast && /usr/bin/make -f CMakeFiles/cmTC_990de.dir/build.make CMakeFiles/cmTC_990de.dir/build
    make[1]: Entering directory '/mnt/c/programming/GitHub/StraightforwardNeuralNetwork/build/CMakeFiles/CMakeTmp'
    Building CXX object CMakeFiles/cmTC_990de.dir/testCXXCompiler.cxx.o
    /usr/bin/c++     -o CMakeFiles/cmTC_990de.dir/testCXXCompiler.cxx.o -c /home/matthieu/StraightforwardNeuralNetwork/build/CMakeFiles/CMakeTmp/testCXXCompiler.cxx
    c++: fatal error: ‘-c’ is not a valid option to the preprocessor
    compilation terminated.
    CMakeFiles/cmTC_990de.dir/build.make:65: recipe for target 'CMakeFiles/cmTC_990de.dir/testCXXCompiler.cxx.o' failed
    make[1]: *** [CMakeFiles/cmTC_990de.dir/testCXXCompiler.cxx.o] Error 1
    make[1]: Leaving directory '/mnt/c/programming/GitHub/StraightforwardNeuralNetwork/build/CMakeFiles/CMakeTmp'
    Makefile:121: recipe for target 'cmTC_990de/fast' failed
    make: *** [cmTC_990de/fast] Error 2

This is very strange because my version of GCC looks good.

matthieu@DESKTOP-PC05NH3:~$ gcc --version
gcc (Ubuntu 9.2.1-17ubuntu1~18.04.1) 9.2.1 20191102
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Same for g++ --version, c++ --version and cpp --version.

For install GCC 9.2 I install gcc-9 and bind to gcc with sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 60

Same for g++, c++ and cpp.

Maybe the error comes from there.
Can you help me please ?

How did you get GCC 9 on Ubuntu 18.04? I don’t see it when I apt search gcc-9 or apt search "gcc 9".

Yes, I have GCC 9.

matthieu@DESKTOP-PC05NH3:~$ apt search gcc-9
Sorting... Done
Full Text Search... Done
gcc-9/bionic,now 9.2.1-17ubuntu1~18.04.1 amd64 [installed]
  GNU C compiler

gcc-9-base/bionic,now 9.2.1-17ubuntu1~18.04.1 amd64 [installed,automatic]
  GCC, the GNU Compiler Collection (base package)

gcc-9-doc/bionic 9.2.1-17ubuntu1~18.04.1 all
  Documentation for the GNU compilers (gcc, gobjc, g++)

gcc-9-hppa64-linux-gnu/bionic 9.2.1-17ubuntu1~18.04.1 amd64
  GNU C compiler (cross compiler for hppa64)

gcc-9-locales/bionic 9.2.1-17ubuntu1~18.04.1 all
  GCC, the GNU compiler collection (native language support files)

gcc-9-multilib/bionic 9.2.1-17ubuntu1~18.04.1 amd64
  GNU C compiler (multilib support)

gcc-9-offload-nvptx/bionic 9.2.1-17ubuntu1~18.04.1 amd64
  GCC offloading compiler to NVPTX

gcc-9-plugin-dev/bionic 9.2.1-17ubuntu1~18.04.1 amd64
  Files for GNU GCC plugin development.

gcc-9-source/bionic 9.2.1-17ubuntu1~18.04.1 all
  Source of the GNU Compiler Collection

gcc-9-test-results/bionic 9.2.1-17ubuntu1~18.04.1 amd64
  Test results for the GCC test suite

lib32gcc-9-dev/bionic 9.2.1-17ubuntu1~18.04.1 amd64
  GCC support library (32 bit development files)

libgcc-9-dev/bionic,now 9.2.1-17ubuntu1~18.04.1 amd64 [installed,automatic]
  GCC support library (development files)

libx32gcc-9-dev/bionic 9.2.1-17ubuntu1~18.04.1 amd64
  GCC support library (x32 development files)

Why my c++ don’t have -c option ?

matthieu@DESKTOP-PC05NH3:~/StraightforwardNeuralNetwork/build$ c++ -c
c++: fatal error: ‘-c’ is not a valid option to the preprocessor
compilation terminated.

Matthieu HERNANDEZ wrote:

Why my c++ don’t have -c option ?

matthieu@DESKTOP-PC05NH3:~/StraightforwardNeuralNetwork/build$ c++ -c
c++: fatal error: ‘-c’ is not a valid option to the preprocessor
compilation terminated.

Just a wild guess: your c++ symlink points to foo-cpp instead of
foo-c++.

Eike

Thanks, I will redo a full installation of Ubuntu and a clean installation of cmake 3.16 and gcc-9 then I tell you again.