MaskRay / ccls

C/C++/ObjC language server supporting cross references, hierarchies, completion and semantic highlighting
Apache License 2.0
3.73k stars 255 forks source link

Build issue on macOS Big Sur #855

Open isundaylee opened 2 years ago

isundaylee commented 2 years ago

Observed behavior

When trying to build ccls on macOS Big Sur, the initial cmake step fails with

-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- broken
CMake Error at /Applications/CMake.app/Contents/share/cmake-3.13/Modules/CMakeTestCCompiler.cmake:52 (message):
  The C compiler

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

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /Users/jiahaoli/Programming/Git/ccls/Release/CMakeFiles/CMakeTmp

    Run Build Command:"/usr/local/bin/gmake" "cmTC_db05b/fast"
    /usr/local/bin/gmake -f CMakeFiles/cmTC_db05b.dir/build.make CMakeFiles/cmTC_db05b.dir/build
    gmake[1]: Entering directory '/Users/jiahaoli/Programming/Git/ccls/Release/CMakeFiles/CMakeTmp'
    Building C object CMakeFiles/cmTC_db05b.dir/testCCompiler.c.o
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc   -mmacosx-version-min=11.2   -o CMakeFiles/cmTC_db05b.dir/testCCompiler.c.o   -c /Users/jiahaoli/Programming/Git/ccls/Release/CMakeFiles/CMakeTmp/testCCompiler.c
    Linking C executable cmTC_db05b
    /Applications/CMake.app/Contents/bin/cmake -E cmake_link_script CMakeFiles/cmTC_db05b.dir/link.txt --verbose=1
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc   -mmacosx-version-min=11.2 -Wl,-search_paths_first -Wl,-headerpad_max_install_names   CMakeFiles/cmTC_db05b.dir/testCCompiler.c.o  -o cmTC_db05b
    ld: library not found for -lSystem
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    gmake[1]: *** [CMakeFiles/cmTC_db05b.dir/build.make:87: cmTC_db05b] Error 1
    gmake[1]: Leaving directory '/Users/jiahaoli/Programming/Git/ccls/Release/CMakeFiles/CMakeTmp'
    gmake: *** [Makefile:121: cmTC_db05b/fast] Error 2

Passing an extra library path to cmake seems to solve this (as in the following works):

cmake -E env LDFLAGS="-L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/" cmake -H. -BRelease -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=/usr/local/Cellar/llvm/13.0.0_2/lib/cmake

Not sure if this is an issue with the new macOS version. If this cannot be fixed from inside ccls, maybe worth a mention in the build Wiki page?

Expected behavior

The initial cmake step works without having to pass in LDFLAGS.

Steps to reproduce

  1. Checkout HEAD
  2. cmake -H. -BRelease -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=/usr/local/Cellar/llvm/13.0.0_2/lib/cmake
  3. The error message above is displayed.

System information