我编译ccls时遇到了困难,不知道是我的环境哪里出了问题。
环境: Ubuntu 16.04,clang-llvm 7.0.1
按照宋教授的Wiki中的指令运行,运用的就是Prebuilt的16.04的Binaries。
$ cmake -H. -BRelease -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=/path/to/clang+llvm-xxx
$ cmake --build Release
然后我先碰见了第一个错,找不到<optional>
头文件。经过一番Google和试验,我强行在CMakeLists.txt
里加了这么一句
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
好,编译没有问题了,全部通过,结果出现了链接错误,在我一波瞎试后以失败而告终 。求助各位如何解决。感谢!!
PS:
部分Error Msg如下,完整的有一万多行
......
/data/terrytsao/software/clang+llvm-7.0.1-x86_64-linux-gnu-ubuntu-16.04/lib/libLLVMSupport.a(TargetRegistry.cpp.o): In function `llvm::TargetRegistry::lookupTarget(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, llvm::Triple&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)':
TargetRegistry.cpp:(.text._ZN4llvm14TargetRegistry12lookupTargetERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS_6TripleERS6_+0x38): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::compare(char const*) const'
TargetRegistry.cpp:(.text._ZN4llvm14TargetRegistry12lookupTargetERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS_6TripleERS6_+0x7d): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::reserve(unsigned long)'
TargetRegistry.cpp:(.text._ZN4llvm14TargetRegistry12lookupTargetERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS_6TripleERS6_+0xa8): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
TargetRegistry.cpp:(.text._ZN4llvm14TargetRegistry12lookupTargetERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS_6TripleERS6_+0xb9): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
TargetRegistry.cpp:(.text._ZN4llvm14TargetRegistry12lookupTargetERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS_6TripleERS6_+0xde): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
TargetRegistry.cpp:(.text._ZN4llvm14TargetRegistry12lookupTargetERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS_6TripleERS6_+0x192): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::swap(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)'
TargetRegistry.cpp:(.text._ZN4llvm14TargetRegistry12lookupTargetERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS_6TripleERS6_+0x1f8): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::reserve(unsigned long)'
TargetRegistry.cpp:(.text._ZN4llvm14TargetRegistry12lookupTargetERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS_6TripleERS6_+0x223): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
TargetRegistry.cpp:(.text._ZN4llvm14TargetRegistry12lookupTargetERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS_6TripleERS6_+0x232): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
TargetRegistry.cpp:(.text._ZN4llvm14TargetRegistry12lookupTargetERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS_6TripleERS6_+0x257): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
TargetRegistry.cpp:(.text._ZN4llvm14TargetRegistry12lookupTargetERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS_6TripleERS6_+0x2ab): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::swap(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)'
TargetRegistry.cpp:(.text._ZN4llvm14TargetRegistry12lookupTargetERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS_6TripleERS6_+0x2e8): undefined reference to `std::__throw_length_error(char const*)'
/data/terrytsao/software/clang+llvm-7.0.1-x86_64-linux-gnu-ubuntu-16.04/lib/libLLVMSupport.a(TargetRegistry.cpp.o): In function `llvm::TargetRegistry::lookupTarget(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)':
TargetRegistry.cpp:(.text._ZN4llvm14TargetRegistry12lookupTargetERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERS6_+0xf4): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned long&, unsigned long)'
TargetRegistry.cpp:(.text._ZN4llvm14TargetRegistry12lookupTargetERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERS6_+0x152): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
TargetRegistry.cpp:(.text._ZN4llvm14TargetRegistry12lookupTargetERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERS6_+0x1af): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_replace(unsigned long, unsigned long, char const*, unsigned long)'
TargetRegistry.cpp:(.text._ZN4llvm14TargetRegistry12lookupTargetERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERS6_+0x20c): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
TargetRegistry.cpp:(.text._ZN4llvm14TargetRegistry12lookupTargetERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERS6_+0x280): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
TargetRegistry.cpp:(.text._ZN4llvm14TargetRegistry12lookupTargetERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERS6_+0x2e8): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
TargetRegistry.cpp:(.text._ZN4llvm14TargetRegistry12lookupTargetERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERS6_+0x347): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::swap(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)'
TargetRegistry.cpp:(.text._ZN4llvm14TargetRegistry12lookupTargetERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERS6_+0x3b1): undefined reference to `std::__throw_length_error(char const*)'
/data/terrytsao/software/clang+llvm-7.0.1-x86_64-linux-gnu-ubuntu-16.04/lib/libLLVMSupport.a(Threading.cpp.o): In function `llvm::heavyweight_hardware_concurrency()':
Threading.cpp:(.text._ZN4llvm32heavyweight_hardware_concurrencyEv+0xf): undefined reference to `std::thread::hardware_concurrency()'
/data/terrytsao/software/clang+llvm-7.0.1-x86_64-linux-gnu-ubuntu-16.04/lib/libLLVMSupport.a(Threading.cpp.o): In function `llvm::hardware_concurrency()':
Threading.cpp:(.text._ZN4llvm20hardware_concurrencyEv+0x34): undefined reference to `std::thread::hardware_concurrency()'
/data/terrytsao/software/clang+llvm-7.0.1-x86_64-linux-gnu-ubuntu-16.04/lib/libLLVMSupport.a(Errno.cpp.o): In function `llvm::sys::StrError[abi:cxx11]()':
Errno.cpp:(.text._ZN4llvm3sys8StrErrorB5cxx11Ev+0x5c): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_replace(unsigned long, unsigned long, char const*, unsigned long)'
/data/terrytsao/software/clang+llvm-7.0.1-x86_64-linux-gnu-ubuntu-16.04/lib/libLLVMSupport.a(Errno.cpp.o): In function `llvm::sys::StrError[abi:cxx11](int)':
Errno.cpp:(.text._ZN4llvm3sys8StrErrorB5cxx11Ei+0x5a): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_replace(unsigned long, unsigned long, char const*, unsigned long)'
clang-7: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [ccls] Error 1
make[1]: *** [CMakeFiles/ccls.dir/all] Error 2
make: *** [all] Error 2