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?

1 Like

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.

I get the same error using both homebrew, and the official CMake release.

Using cmake downloaded from https://github.com/Kitware/CMake/releases/download/v3.21.4/cmake-3.21.4-macos-universal.dmg

❯ /Applications/CMake.app/Contents/bin/cmake .
CMake Warning at /Applications/CMake.app/Contents/share/cmake-3.22/Modules/Platform/Darwin-Initialize.cmake:303 (message):
  Ignoring CMAKE_OSX_SYSROOT value:

   /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk

  because the directory does not exist.
Call Stack (most recent call first):
  /Applications/CMake.app/Contents/share/cmake-3.22/Modules/CMakeSystemSpecificInitialize.cmake:21 (include)
  CMakeLists.txt:2 (project)


-- The CXX compiler identification is AppleClang 13.0.0.13000029
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - broken
CMake Error at /Applications/CMake.app/Contents/share/cmake-3.22/Modules/CMakeTestCXXCompiler.cmake:62 (message):
  The C++ compiler

    "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /Users/jthomas/git-projects/coscreen-screen-capturer/CMakeFiles/CMakeTmp

    Run Build Command(s):/usr/bin/make -f Makefile cmTC_6006a/fast && /Applications/Xcode.app/Contents/Developer/usr/bin/make  -f CMakeFiles/cmTC_6006a.dir/build.make CMakeFiles/cmTC_6006a.dir/build
    Building CXX object CMakeFiles/cmTC_6006a.dir/testCXXCompiler.cxx.o
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++   -arch x86_64 -mmacosx-version-min=11.5 -MD -MT CMakeFiles/cmTC_6006a.dir/testCXXCompiler.cxx.o -MF CMakeFiles/cmTC_6006a.dir/testCXXCompiler.cxx.o.d -o CMakeFiles/cmTC_6006a.dir/testCXXCompiler.cxx.o -c /Users/jthomas/git-projects/coscreen-screen-capturer/CMakeFiles/CMakeTmp/testCXXCompiler.cxx
    Linking CXX executable cmTC_6006a
    /Applications/CMake.app/Contents/bin/cmake -E cmake_link_script CMakeFiles/cmTC_6006a.dir/link.txt --verbose=1
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++  -arch x86_64 -mmacosx-version-min=11.5 -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/cmTC_6006a.dir/testCXXCompiler.cxx.o -o cmTC_6006a
    ld: library not found for -lc++
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    make[1]: *** [cmTC_6006a] Error 1
    make: *** [cmTC_6006a/fast] Error 2





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


-- Configuring incomplete, errors occurred!

I think it’s some incompatibility with the new MacOSX SDK/toolchain?

The SDK directory not existing certainly sounds important. Did Xcode get updated and bring in a new SDK version (maybe 11.4?). I think there’s an unversioned symlink (MacOSX.sdk); you may have better post-update luck with using that name.

@ben.boeckel

Yeah, that’s exactly what’s happening.

Updating XCode blows away your

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs 

directory and makes a single directory containing only MacOSX12.0.sdk pointing at MacOSX.sdk.

This seems to suffer from a lack of libc++.dylib being present… Maybe due to something having to do with how Big Sur loads libraries (not sure if I understand it)?

https://developer.apple.com/forums/thread/666700

The following steps resolved it for me:

# cd `xcode-select -p`/
# cd Platforms/MacOSX.platform/Developer/SDKs/
# git clone https://github.com/phracker/MacOSX-SDKs.git
# cp -r MacOSX-SDKs/MacOSX11.3.sdk .

And then I made sure CMAKE_OSX_SYSROOT was pointing at:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk
1 Like

not working for me, got confused.

Yeah, the system libraries themselves now live off in some system-wide library cache. The .tbd files have the information the linker needs to figure out what to do.

Note that the way Apple works, you should be able to use any new-enough SDK and use -mmacosx-min-version= to restrict API usage of anything newer than that version. See CMAKE_OSX_DEPLOYMENT_TARGET for the CMake knob to handle that (you want =11.3 here).

2 Likes

As an FYI, I just ran into this myself. Specifically the compiler test failed with:

ld: library not found for -lSystem

Running the following fixed things for me. I don’t need anything but the default SDKs.

$ sudo rm -rf /Library/Developer/CommandLineTools
$ xcode-select --install

FYI if you get here from trying to compile with Intel.
https://community.intel.com/t5/Intel-C-Compiler/How-to-use-the-Intel-Classic-C-Compiler-with-macOS-11-Big-Sur/m-p/1295419

In case someone is still struggling with this, I fixed it by updating my SDKROOT variable

export SDKROOT=$(xcrun --sdk macosx --show-sdk-path)

1 Like

This!

Though was seeing it through in the form: ld: library not found for -lSystem

Thanks for the workaround fellas, that saved me after already blowing away half my day on this on red herrings and thinking it was a paths issue.

It seems like this is a rising issue since as the upgraded MacOSX12 sdk does not contain what’s needed the 11.3 sdk must be used – an earlier post in this thread also confirms this. On other words, what happens when that 11.3 sdk is no longer available (or if we don’t want link to against a rando github SDK provider).