cmake not working after update do Big Sur

After updating to Big Sur, I am unable to compile anything with cmake. I re-installed the command line tools (xcode-select --install) and updated cmake (brew upgrade cmake). When running cmake -S ./ -B ./bin -G "Unix Makefiles" i get the output:

-- The C compiler identification is AppleClang 12.0.0.12000032
-- The CXX compiler identification is AppleClang 12.0.0.12000032
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /usr/bin/clang
-- Check for working C compiler: /usr/bin/clang - broken
CMake Error at /usr/local/Cellar/cmake/3.19.3/share/cmake/Modules/CMakeTestCCompiler.cmake:66 (message):
  The C compiler
    "/usr/bin/clang"
  is not able to compile a simple test program.
  It fails with the following output:
    /usr/bin/clang  -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk -o CMakeFiles/cmTC_b5a37.dir/testCCompiler.c.o -c /Users/harniver/Git/aggregate/fcpp/fcpp/bin/CMakeFiles/CMakeTmp/testCCompiler.c
    /usr/bin/clang  -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names -static  CMakeFiles/cmTC_b5a37.dir/testCCompiler.c.o -o cmTC_b5a37
    ld: library not found for -lcrt0.o
    clang: error: linker command failed with exit code 1 (use -v to see invocation)

In other projects I get similar error except that the missing library is something else (-lSystem, for example). Any ideas on what may be going wrong?

@brad.king

Have you started up the Xcode IDE since you installed it? There may be missing components or a license may need to be accepted. Both of these seem unlikely though.

Also, have a look at the CMakeFiles/CMakeError.log and CMakeFiles/CMakeOutput.log files in your build directory and see if there are any clues in there for what might be going on.

Yes, I have used the Xcode IDE (and to be sure I just used it again and re-tried with no difference). The CMakeError/CMakeOutput files are very big and it’s hard for me to make any sense from them. I can see that in CMakeError there are several occurrences of these:

ld: library not found for -lSystem
ld: library not found for -lc++

Do you have suggestion on some things to look for in those files?

Another thought, have you tried the official CMake package from cmake.org/download? It would be good to rule out a problem caused by how brew builds/provides CMake.

Where you see those “library not found” errors in the CMakeError.log file, what’s the command line just before it that causes those errors?

What version of Xcode are you using? If it isn’t the latest, please try the latest to confirm whether you still see the issue.

Do you get the same error if you try to use the Xcode generator instead of Unix Makefiles? A useful side effect of using the Xcode generator is that the try_compile() run used during compiler checks creates a temporary Xcode project that you can open up in the Xcode IDE and look for any suspicious settings.

Does your project have anything other than a call to cmake_minimum_required() before the first project() call?

I just tried again to build the library and the problem seems to have fixed itself (not clear exactly what happened). Thanks anyway for the help!

I also have the same issue on an Intel MBP running Big Sur. I tried EVERYTHING™, even format and clean reinstall of Bug Sur 11.3, homebrew (installing cmake 3.20.1), and the full Xcode and 12.5 (also tried command line tools).

Compiling the C compiler identification source file "CMakeCCompilerId.c" failed.
Compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc 
Build flags: 
Id flags:  

The output was:
1
ld: library not found for -lSystem
clang: error: linker command failed with exit code 1 (use -v to see invocation)


Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
Compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ 
Build flags: 
Id flags:  

The output was:
1
ld: library not found for -lc++
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Any feedback is highly appreciated!

Try using the official CMake release rather than the one from homebrew. That should help narrow down whether your issue is homebrew-related or something else.

Has anyone solved this yet? I’m on Big Sur 11.5.2, Xcode 12.5.1. Have tried with CMake 3.18.6 and 3.21.2. I get the same output as Kamyar’s post of Apr 28. It only happens when my generator is “Unix Makefiles”. I was able to get another project built with CMake on Big Sur whose generator was “Xcode”.

Same advice as above: are you using CMake provided by homebrew or the official release from Kitware? If you’re using the one from homebrew, try the official release instead. If that fixes your problem, please report back here.