MaskRay / ccls

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

Linker error: undefined reference in libclang-cpp #935

Closed jg110 closed 1 year ago

jg110 commented 1 year ago

Observed behavior

ccls compiles successfully but fails at the linking step. I've tried building with clang+LLVM 16, 15, 14, and 13. I've also tried with Makefile and Ninja outputs of cmake. Compiler is GCC.

Build log:

$ cmake -H. -BRelease
-- The CXX compiler identification is GNU 11.2.0
-- The C compiler identification is GNU 13.0.1
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/lib64/ccache/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/lib64/ccache/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Setting build type to 'Release' as none was specified.
-- Performing Test HAVE_FFI_CALL
-- Performing Test HAVE_FFI_CALL - Success
-- Found FFI: /usr/lib64/libffi.so  
-- Performing Test Terminfo_LINKABLE
-- Performing Test Terminfo_LINKABLE - Success
-- Found Terminfo: /usr/lib64/libtinfo.so  
-- Found ZLIB: /usr/lib64/libz.so (found version "1.2.13")  
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- RapidJSON found. Headers: /usr/include
fatal: No names found, cannot describe anything.
-- Configuring done (1.0s)
-- Generating done (0.0s)
-- Build files have been written to: /home/jg110/Documents/repos/ccls/Release

$ cmake --build Release
[  2%] Building CXX object CMakeFiles/ccls.dir/third_party/siphash.cc.o
[  4%] Building CXX object CMakeFiles/ccls.dir/src/clang_tu.cc.o
[  6%] Building CXX object CMakeFiles/ccls.dir/src/config.cc.o
[  9%] Building CXX object CMakeFiles/ccls.dir/src/filesystem.cc.o
[ 11%] Building CXX object CMakeFiles/ccls.dir/src/fuzzy_match.cc.o
[ 13%] Building CXX object CMakeFiles/ccls.dir/src/main.cc.o
[ 16%] Building CXX object CMakeFiles/ccls.dir/src/include_complete.cc.o
[ 18%] Building CXX object CMakeFiles/ccls.dir/src/indexer.cc.o
[ 20%] Building CXX object CMakeFiles/ccls.dir/src/log.cc.o
[ 23%] Building CXX object CMakeFiles/ccls.dir/src/lsp.cc.o
[ 25%] Building CXX object CMakeFiles/ccls.dir/src/message_handler.cc.o
[ 27%] Building CXX object CMakeFiles/ccls.dir/src/pipeline.cc.o
[ 30%] Building CXX object CMakeFiles/ccls.dir/src/platform_posix.cc.o
[ 32%] Building CXX object CMakeFiles/ccls.dir/src/platform_win.cc.o
[ 34%] Building CXX object CMakeFiles/ccls.dir/src/position.cc.o
[ 37%] Building CXX object CMakeFiles/ccls.dir/src/project.cc.o
[ 39%] Building CXX object CMakeFiles/ccls.dir/src/query.cc.o
In file included from /home/jg110/Documents/repos/ccls/src/indexer.hh:6,
                 from /home/jg110/Documents/repos/ccls/src/query.hh:6,
                 from /home/jg110/Documents/repos/ccls/src/query.cc:4:
In constructor ‘ccls::SymbolInformation::SymbolInformation(ccls::SymbolInformation&&)’,
    inlined from ‘constexpr std::_Optional_payload_base<_Tp>::_Storage<_Up, false>::_Storage(std::in_place_t, _Args&& ...) [with _Args = {ccls::SymbolInformation}; _Up = ccls::SymbolInformation; _Tp = ccls::SymbolInformation]’ at /usr/local/include/c++/11.2.0/optional:225:8,
    inlined from ‘constexpr std::_Optional_payload_base<_Tp>::_Optional_payload_base(std::in_place_t, _Args&& ...) [with _Args = {ccls::SymbolInformation}; _Tp = ccls::SymbolInformation]’ at /usr/local/include/c++/11.2.0/optional:116:4,
    inlined from ‘constexpr std::_Optional_payload<ccls::SymbolInformation, true, false, false>::_Optional_payload(std::in_place_t, _Args&& ...) [with _Args = {ccls::SymbolInformation}][inherited from std::_Optional_payload_base<ccls::SymbolInformation>]’ at /usr/local/include/c++/11.2.0/optional:358:42,
    inlined from ‘constexpr std::_Optional_payload<ccls::SymbolInformation, false, false, false>::_Optional_payload(std::in_place_t, _Args&& ...) [with _Args = {ccls::SymbolInformation}][inherited from std::_Optional_payload_base<ccls::SymbolInformation>]’ at /usr/local/include/c++/11.2.0/optional:392:57,
    inlined from ‘constexpr std::_Optional_base<_Tp, <anonymous>, <anonymous> >::_Optional_base(std::in_place_t, _Args&& ...) [with _Args = {ccls::SymbolInformation}; typename std::enable_if<is_constructible_v<_Tp, _Args ...>, bool>::type <anonymous> = false; _Tp = ccls::SymbolInformation; bool <anonymous> = false; bool <anonymous> = false]’ at /usr/local/include/c++/11.2.0/optional:484:4,
    inlined from ‘constexpr std::optional<_Tp>::optional(_Up&&) [with _Up = ccls::SymbolInformation; typename std::enable_if<__and_v<std::__not_<std::is_same<std::optional<_Tp>, typename std::remove_cv<typename std::remove_reference<_Up>::type>::type> >, std::__not_<std::is_same<std::in_place_t, typename std::remove_cv<typename std::remove_reference<_Up>::type>::type> >, std::is_constructible<_Tp, _Up>, std::is_convertible<_Up, _Tp> >, bool>::type <anonymous> = true; _Tp = ccls::SymbolInformation]’ at /usr/local/include/c++/11.2.0/optional:707:47,
    inlined from ‘std::optional<ccls::SymbolInformation> ccls::getSymbolInfo(ccls::DB*, ccls::SymbolIdx, bool)’ at /home/jg110/Documents/repos/ccls/src/query.cc:779:12:
/home/jg110/Documents/repos/ccls/src/lsp.hh:179:8: warning: ‘info.ccls::SymbolInformation::kind’ may be used uninitialized [-Wmaybe-uninitialized]
  179 | struct SymbolInformation {
      |        ^~~~~~~~~~~~~~~~~
/home/jg110/Documents/repos/ccls/src/query.cc: In function ‘std::optional<ccls::SymbolInformation> ccls::getSymbolInfo(ccls::DB*, ccls::SymbolIdx, bool)’:
/home/jg110/Documents/repos/ccls/src/query.cc:770:23: note: ‘info’ declared here
  770 |     SymbolInformation info;
      |                       ^~~~
[ 41%] Building CXX object CMakeFiles/ccls.dir/src/sema_manager.cc.o
[ 44%] Building CXX object CMakeFiles/ccls.dir/src/serializer.cc.o
[ 46%] Building CXX object CMakeFiles/ccls.dir/src/test.cc.o
[ 48%] Building CXX object CMakeFiles/ccls.dir/src/utils.cc.o
[ 51%] Building CXX object CMakeFiles/ccls.dir/src/working_files.cc.o
[ 53%] Building CXX object CMakeFiles/ccls.dir/src/messages/ccls_call.cc.o
[ 55%] Building CXX object CMakeFiles/ccls.dir/src/messages/ccls_info.cc.o
[ 58%] Building CXX object CMakeFiles/ccls.dir/src/messages/ccls_inheritance.cc.o
[ 60%] Building CXX object CMakeFiles/ccls.dir/src/messages/ccls_member.cc.o
[ 62%] Building CXX object CMakeFiles/ccls.dir/src/messages/ccls_navigate.cc.o
[ 65%] Building CXX object CMakeFiles/ccls.dir/src/messages/ccls_reload.cc.o
[ 67%] Building CXX object CMakeFiles/ccls.dir/src/messages/ccls_vars.cc.o
[ 69%] Building CXX object CMakeFiles/ccls.dir/src/messages/initialize.cc.o
[ 72%] Building CXX object CMakeFiles/ccls.dir/src/messages/textDocument_code.cc.o
[ 74%] Building CXX object CMakeFiles/ccls.dir/src/messages/textDocument_completion.cc.o
[ 76%] Building CXX object CMakeFiles/ccls.dir/src/messages/textDocument_definition.cc.o
[ 79%] Building CXX object CMakeFiles/ccls.dir/src/messages/textDocument_did.cc.o
[ 81%] Building CXX object CMakeFiles/ccls.dir/src/messages/textDocument_foldingRange.cc.o
[ 83%] Building CXX object CMakeFiles/ccls.dir/src/messages/textDocument_formatting.cc.o
[ 86%] Building CXX object CMakeFiles/ccls.dir/src/messages/textDocument_document.cc.o
[ 88%] Building CXX object CMakeFiles/ccls.dir/src/messages/textDocument_hover.cc.o
[ 90%] Building CXX object CMakeFiles/ccls.dir/src/messages/textDocument_references.cc.o
[ 93%] Building CXX object CMakeFiles/ccls.dir/src/messages/textDocument_rename.cc.o
[ 95%] Building CXX object CMakeFiles/ccls.dir/src/messages/textDocument_signatureHelp.cc.o
[ 97%] Building CXX object CMakeFiles/ccls.dir/src/messages/workspace.cc.o
[100%] Linking CXX executable ccls
/usr/bin/ld: /usr/lib64/libclang-cpp.so.16: undefined reference to `std::condition_variable::wait(std::unique_lock<std::mutex>&)@GLIBCXX_3.4.30'
/usr/bin/ld: /usr/lib64/libclang-cpp.so.16: undefined reference to `std::__glibcxx_assert_fail(char const*, int, char const*, char const*)@GLIBCXX_3.4.30'
collect2: error: ld returned 1 exit status
gmake[2]: *** [CMakeFiles/ccls.dir/build.make:755: ccls] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:88: CMakeFiles/ccls.dir/all] Error 2
gmake: *** [Makefile:136: all] Error 2

I've checked both strings /usr/lib64/libstdc++.6.0.31 and strings /usr/lib64/libclang-cpp.so.16 and they contain GLIBCXX_3.4.30 (as do the older versions of libclang-cpp I've tested).

Expected behavior

ccls should link correctly.

Steps to reproduce

  1. Clone ccls repo at the latest version of master
  2. cd into ccls, cmake -H. -BRelease and cmake --build Release

System information

jg110 commented 1 year ago

I believe I've tracked this down to a compiler configuration error - the CXX compiler should be GNU 13.0.1, not 11.2.0. Closing this unless correcting that turns out not to fix the issue.

jg110 commented 1 year ago

Following up on this to confirm, it was an issue with my compiler setup. I had manually compiled a few older versions of gcc for a different project a year ago and ccache automatically grabbed one of those (which still probably wouldn't have caused a problem if the C and C++ compilers were the same version). Removing the old GCC and using the regular packaged version (both at 13.0.1) fixed the problem.