'CMake Error when compiling a project on Clion

I haven't been using Clion for some time and these days I tried to run an old project and it gave me this compile error (It used to work fine). Then I created a new project to test, the error still persists. I also tried to update my Clion. Here is the error message:

/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=/Applications/CLion.app/Contents/bin/ninja/mac/ninja -DCMAKE_CXX_COMPILER=/usr/local/Cellar/gcc/9.2.0_1/bin/g++-9 -G Ninja /Users/yzr/Desktop/untitled
-- The C compiler identification is AppleClang 13.0.0.13000029
-- The CXX compiler identification is unknown
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Check for working CXX compiler: /usr/local/Cellar/gcc/9.2.0_1/bin/g++-9
-- Check for working CXX compiler: /usr/local/Cellar/gcc/9.2.0_1/bin/g++-9 - broken
CMake Error at /Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.21/Modules/CMakeTestCXXCompiler.cmake:62 (message):
  The C++ compiler

    "/usr/local/Cellar/gcc/9.2.0_1/bin/g++-9"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /Users/yzr/Desktop/untitled/cmake-build-debug/CMakeFiles/CMakeTmp
    
    Run Build Command(s):/Applications/CLion.app/Contents/bin/ninja/mac/ninja cmTC_5a895 && [1/2] Building CXX object CMakeFiles/cmTC_5a895.dir/testCXXCompiler.cxx.o
    FAILED: CMakeFiles/cmTC_5a895.dir/testCXXCompiler.cxx.o 
    /usr/local/Cellar/gcc/9.2.0_1/bin/g++-9    -o CMakeFiles/cmTC_5a895.dir/testCXXCompiler.cxx.o -c /Users/yzr/Desktop/untitled/cmake-build-debug/CMakeFiles/CMakeTmp/testCXXCompiler.cxx
    dyld: Library not loaded: /usr/local/opt/isl/lib/libisl.21.dylib
      Referenced from: /usr/local/Cellar/gcc/9.2.0_1/libexec/gcc/x86_64-apple-darwin18/9.2.0/cc1plus
      Reason: image not found
    g++-9: internal compiler error: Abort trap: 6 signal terminated program cc1plus
    Please submit a full bug report,
    with preprocessed source if appropriate.
    See <https://github.com/Homebrew/homebrew-core/issues> for instructions.
    ninja: build stopped: subcommand failed.
    
    

  

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:2 (project)


-- Configuring incomplete, errors occurred!
See also "/Users/yzr/Desktop/untitled/cmake-build-debug/CMakeFiles/CMakeOutput.log".
See also "/Users/yzr/Desktop/untitled/cmake-build-debug/CMakeFiles/CMakeError.log".

Here is how my CMakeList.txt looks like:

cmake_minimum_required(VERSION 3.21)
project(untitled)

set(CMAKE_CXX_STANDARD 14)

add_executable(untitled main.cpp)

I read this post and added the environment variable but it doesn't seem to work. This is really weird, as it all worked fine. It's just I didn't touch it for some time and need to take a look now. Has anyone encountered this before? Thanks!



Solution 1:[1]

Maybe you can try to delete the previous generated cmake-build-debug directory. As the outside environment and version may be updated, some information generated in previous cmake-build-debug directory may no longer be useful. So delete it and Reload the make file to see whether the problem could be solved.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Wen Keing