这个 import_pipeline 改过之后准了好多……
想听详细的诊断信息。
有在用cquery的我想知道
前後記憶體佔用對比
https://github.com/melpa/melpa/pull/5405 合併了
可以用 MELPA 了。https://github.com/MaskRay/ccls/wiki/Getting-started加了幾個常見系統最方便的配置
FreeBSD
11: cmake -H. -Brelease -DCLANG_USE_BUNDLED_LIBC++=on
12: cmake -H. -Brelease -DSYSTEM_CLANG=on
DEFCON偷偷摸個魚還要怕被強網盃大佬抓住
玩 C 的都是大佬
aur里面的第29行是错的,把..
放到了前面,把我坑了。。。我改成了
cmake -H. -Brelease -DSYSTEM_CLANG=On ..
user-error: Could not find ccls project root
是怎么回事?不管是.ccls
在当前目录或者compile_commands.json
在上层目录都不行。
我是通过添加c-mode-common-hook
的lambda中有一行(lsp-ccls-enable)
来开启的。
把配置中的ccls
全换成cquery
,但可执行文件设成ccls
的话可行,就是每次Mark set
会很卡。。。
不是啊,我makepkg成功了的。
现在问题是找不到项目根目录。log就是我之前回复的第一行。
那个参数的话,我不知道什么意思,不过cmake的命令行里面,目录要放在最后面,aur里面放在了前面,然后报错了。如果..
和那个冲突的话,那正确的应该就是把..
放后面吧,反正我那样改是成功了的。
在 macOS 10.11.6 下无法编译了:
└⋊> brew install https://raw.githubusercontent.com/twlz0ne/homebrew-ccls/master/Formula/ccls.rb --HEAD
==> Cloning https://github.com/MaskRay/ccls.git
Updating ~/.cache/homebrew/ccls--git
==> Checking out branch master
Synchronizing submodule url for 'thirdparty/gtest'
==> mkdir -p release
==> cmake -DCMAKE_C_FLAGS_RELEASE=-DNDEBUG -DCMAKE_CXX_FLAGS_RELEASE=-DNDEBUG -DCMAKE_INSTALL_PREFIX=/usr/local/Cellar/ccls/HEAD-111a2a8 -DCMAKE_BUILD_TYPE=Release -DCMAKE_FIND_FRAMEWORK=LAST -DCMAKE_VERBOSE_MAKEFILE=ON -Wno-dev -DHAVE_CLOCK_GETTIME:INTERNAL=0 -DSYSTEM_CL
==> cmake --build release --target install
Last 15 lines from ~/Library/Logs/Homebrew/ccls/03.cmake:
clang::vfs::directory_iterator::increment(std::__1::error_code&) in libclangDriver.a(Gnu.cpp.o)
clang::vfs::directory_iterator::increment(std::__1::error_code&) in libclangDriver.a(BareMetal.cpp.o)
"_compress2", referenced from:
llvm::zlib::compress(llvm::StringRef, llvm::SmallVectorImpl<char>&, llvm::zlib::CompressionLevel) in libLLVMSupport.a(Compression.cpp.o)
"_compressBound", referenced from:
llvm::zlib::compress(llvm::StringRef, llvm::SmallVectorImpl<char>&, llvm::zlib::CompressionLevel) in libLLVMSupport.a(Compression.cpp.o)
"_crc32", referenced from:
llvm::zlib::crc32(llvm::StringRef) in libLLVMSupport.a(Compression.cpp.o)
"_uncompress", referenced from:
llvm::zlib::uncompress(llvm::StringRef, char*, unsigned long&) in libLLVMSupport.a(Compression.cpp.o)
ld: symbol(s) not found for architecture x86_64
clang-6.0: 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
详情 https://pastebin.com/raw/0SMwMDKg
UPDATE
看详细编译日志当中 clang++
这一行,只引用了 4 个 llvm/lib/libXXX.a
文件,后面报错的函数则需要链接到其它文件(例如 tryParse()
<–> libclanBasic.a
):
/usr/local/opt/llvm/bin/clang++ -DNDEBUG -Wl,-search_paths_first -Wl,-headerpad_max_install_names \
CMakeFiles/ccls.dir/third_party/siphash.cc.o \
... \
CMakeFiles/ccls.dir/src/messages/workspace_symbol.cc.o -o ccls /usr/local/opt/llvm/lib/libclang.dylib /usr/local/opt/llvm/lib/libclang.dylib /usr/lib/libcurses.dylib /usr/lib/libform.dylib -lc++experimental \
/usr/local/opt/llvm/lib/libclangDriver.a \
/usr/local/opt/llvm/lib/libLLVMOption.a \
/usr/local/opt/llvm/lib/libLLVMSupport.a \
/usr/local/opt/llvm/lib/libLLVMDemangle.a
Undefined symbols for architecture x86_64:
"clang::ObjCRuntime::tryParse(llvm::StringRef)", referenced from:
clang::driver::tools::Clang::AddObjCRuntimeArgs(llvm::opt::ArgList const&, llvm::SmallVector<char const*, 16u>&, clang::driver::tools::Clang::RewriteKind) const in libclangDriver.a(Clang.cpp.o)
謝謝PR,我也發現了,少了clangBasic
. clang/CMakeLists.txt at master · llvm-mirror/clang · GitHub
週末嘗試把一些組件換成clang+llvm C++ API (experimental/filesystem → llvm/Support/FileSystem.h , command line parsing → llvm/Support/CommandLine.h, sparsepp->DenseMap)。cmake裏寫邏輯鏈接llvm有點痛苦
ccls 最新代码仍然会出现我上边那个错误,也有其他人反馈这个问题:Undefined symbol when installing
我打算在 docker (debian9 + clang6 + cmake3.7)里试试,不过一个全新的 linux 环境下想要编译通过并不容易:
CMake Error at /usr/share/cmake-3.7/Modules/FindPackageHandleStandardArgs.cmake:138 (message):
Could NOT find Clang (missing: Clang_LIBRARY Clang_INCLUDE_DIR
Clang_EXECUTABLE Clang_RESOURCE_DIR Clang_VERSION LLVM_INCLUDE_DIR
LLVM_BUILD_INCLUDE_DIR) (Required is at least version "6.0.0")
Call Stack (most recent call first):
/usr/share/cmake-3.7/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
cmake/FindClang.cmake:108 (find_package_handle_standard_args)
CMakeLists.txt:108 (find_package)
Home · MaskRay/ccls Wiki · GitHub 放了两个命令
cmake -H. -Brelease -DCLANG_USE_BUNDLED_LIBC++=on # old clang or libstdc++
cmake -H. -Brelease -DSYSTEM_CLANG=on -DUSE_SHARED_LLVM=on # newer
这个错误是因为 Build · MaskRay/ccls Wiki · GitHub 描述的一些文件没法找到(libclang.so.6
libLLVMSupport.a
clang/c++头文件)
回复了。我猜libLLVM*.a
依赖zlib。但我没有Mac无法测试
libclang.so只有动态库,libclang.so可能会依赖libLLVM-6.0.so,假如可执行文件链接libLLVM*.a,运行时又链接libLLVM-6.0.so,会导致一些static constructor被运行两遍。
我现在是用 docker 编译,从 0 开始的全新环境:
FROM launcher.gcr.io/google/debian9:latest
RUN apt-get update && apt-get install -y gnupg wget software-properties-common
RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
RUN apt-add-repository "deb http://apt.llvm.org/stretch/ llvm-toolchain-stretch-6.0 main"
RUN apt-get update && apt-get install -y clang-6.0
RUN apt-get install -y cmake
RUN echo 'export CMAKE_CXX_COMPILER=/usr/bin/clang++-6.0' >> ~/.bashrc
llvm / clang / cmake 之间的关系有点懵:cmake 目录底下有 clang,llvm 目录底下有 cmake 和 clang,应该导出哪一个?
root@209307af3b10# ls /usr/lib/clang/
6.0 6.0.1
root@60a75a2b9786# ls /usr/lib/llvm-6.0/lib/clang/
6.0.1
root@209307af3b10# ls /usr/lib/llvm-6.0/
bin build cmake include lib share
root@60a75a2b9786# ls /usr/lib/cmake/
clang-6.0
前的错误说 missing: Clang_LIBRARY Clang_INCLUDE_DIR
,但即使编译命令加上 -DCLANG_LIB_DIR=/usr/lib/clang/6.0/lib/ -DCLANG_INCLUDE_DIR=/usr/lib/clang/6.0/include/
仍然同样的错误。
UPDATE 2018-05-15 16.47.04
这里有个跟我一样的问题(只不过他在 macOS,而我现在在 Debian。我在 macOS 反而不会遇到这个问题):cmake libclang with homebrew llvm on macos - Stack Overflow
回帖也说是因为找不到 clang 和 头文件,只要把 CMAKE_PREFIX_PATH
指向 /usr/local/opt/llvm
就可以了。在 macOS 下,/usr/local/opt/llvm
就是 llvm 安装目录的根:
└⋊> ls /usr/local/opt/llvm/
INSTALL_RECEIPT.json LICENSE.TXT README.txt bin/ include/ lib/ libexec/ share/
在我刚刚安装的 debian9 上面,llvm 安装的目录则是/usr/lib/llvm-6.0
:
root@5d4f228af6a3:# ls /usr/lib/llvm-6.0/
bin build cmake include lib share
所以我把编译命令改成:
root@5d4f228af6a3:# cmake -H. -Brelease \
-DCMAKE_CXX_COMPILER=/usr/bin/clang++-6.0 \
-DCMAKE_PREFIX_PATH=/usr/lib/llvm-6.0/ \
-DSYSTEM_CLANG=On \
-DUSE_SHARED_LLVM=on
-- The CXX compiler identification is Clang 6.0.1
-- Check for working CXX compiler: /usr/bin/clang++-6.0
-- Check for working CXX compiler: /usr/bin/clang++-6.0 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Setting build type to 'Release' as none was specified.
-- Using system Clang
CMake Error at /usr/share/cmake-3.7/Modules/FindPackageHandleStandardArgs.cmake:138 (message):
Could NOT find Clang (missing: Clang_LIBRARY Clang_INCLUDE_DIR) (found
suitable version "6.0.1", minimum required is "6.0.0")
Call Stack (most recent call first):
/usr/share/cmake-3.7/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
cmake/FindClang.cmake:108 (find_package_handle_standard_args)
CMakeLists.txt:108 (find_package)
-- Configuring incomplete, errors occurred!
See also "/var/app/release/CMakeFiles/CMakeOutput.log".
仍然找不到 Clang。
UPDATE 2018-05-15 17.30.17
另外说一下,在 macOS 编译这个分支(也就是前天的代码)是可以过的:GitHub - twlz0ne/ccls at add-clangbasic-to-cmake
但是 ccls 最新的代码却编译不过,所以我就试着从 0 开始搭建一个 linux 编译环境,看看会遇到什么情况。
完整的编译过程放到 gist 了,只需顺序粘贴执行,问题 100% 可重现。
# /usr/lib/clang/6.0.1 是resource directory,clang -print-resource-dir 可能會打印這個目錄
root@209307af3b10# ls /usr/lib/clang/
6.0 6.0.1
# 我猜 /usr/lib/llvm-6.0/lib/clang/6.0.1 和 /usr/lib/clang/6.0.1 其中一個是另一個的 symlink。即使不是,下面的內容應該一致
root@60a75a2b9786# ls /usr/lib/llvm-6.0/lib/clang/
6.0.1
# 把 /usr/lib/llvm-6.0 添加到CMAKE_PREFIX_PATH 應該能找到
# * llvm include path: /usr/lib/llvm-6.0/include/llvm/**
# * clang include path: /usr/lib/llvm-6.0/include/clang/**
# * clang/llvm libraries: /usr/lib/llvm-6.0/lib/
# 我懷疑 cmake 還有哪些魔法,/usr/lib/llvm-6.0 會被自動加到搜索路徑;但我對cmake不瞭解
root@209307af3b10# ls /usr/lib/llvm-6.0/
bin build cmake include lib share
# 可能這是 cmake 找llvm路徑的魔法來源?
root@60a75a2b9786# ls /usr/lib/cmake/
clang-6.0
终于有了进展。顺便把脚本做了点改进( gist ),运行 ./build.sh
自动完成获取代码、创建 docker、编译等系列操作。
不过在 cmake --build release
还是遇到了错误:
/opt/cmake/bin/cmake -H/ccls -B/ccls/release --check-build-system CMakeFiles/Makefile.cmake 0
/opt/cmake/bin/cmake -E cmake_progress_start /ccls/release/CMakeFiles /ccls/release/CMakeFiles/progress.marks
/usr/bin/make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/ccls/release'
/usr/bin/make -f CMakeFiles/ccls.dir/build.make CMakeFiles/ccls.dir/depend
make[2]: Entering directory '/ccls/release'
cd /ccls/release && /opt/cmake/bin/cmake -E cmake_depends "Unix Makefiles" /ccls /ccls /ccls/release /ccls/release /ccls/release/CMakeFiles/ccls.dir/DependInfo.cmake --color=
Scanning dependencies of target ccls
make[2]: Leaving directory '/ccls/release'
/usr/bin/make -f CMakeFiles/ccls.dir/build.make CMakeFiles/ccls.dir/build
make[2]: Entering directory '/ccls/release'
[ 1%] Building CXX object CMakeFiles/ccls.dir/third_party/siphash.cc.o
/usr/bin/clang++-6.0 -DDEFAULT_RESOURCE_DIRECTORY=\"/usr/lib/llvm-6.0/lib/clang/6.0.1\" -DLOGURU_FILENAME_WIDTH=18 -DLOGURU_THREADNAME_WIDTH=13 -DLOGURU_WITH_STREAMS=1 -I/ccls/src -I/ccls/third_party -I/ccls/third_party/rapidjson/include -I/ccls/third_party/loguru -I/ccls/third_party/doctest -isystem /usr/lib/llvm-6.0/include -O3 -DNDEBUG -fno-rtti -Wall -Wno-sign-compare -pthread -std=c++1z -o CMakeFiles/ccls.dir/third_party/siphash.cc.o -c /ccls/third_party/siphash.cc
[ 2%] Building CXX object CMakeFiles/ccls.dir/src/cache_manager.cc.o
/usr/bin/clang++-6.0 -DDEFAULT_RESOURCE_DIRECTORY=\"/usr/lib/llvm-6.0/lib/clang/6.0.1\" -DLOGURU_FILENAME_WIDTH=18 -DLOGURU_THREADNAME_WIDTH=13 -DLOGURU_WITH_STREAMS=1 -I/ccls/src -I/ccls/third_party -I/ccls/third_party/rapidjson/include -I/ccls/third_party/loguru -I/ccls/third_party/doctest -isystem /usr/lib/llvm-6.0/include -O3 -DNDEBUG -fno-rtti -Wall -Wno-sign-compare -pthread -std=c++1z -o CMakeFiles/ccls.dir/src/cache_manager.cc.o -c /ccls/src/cache_manager.cc
In file included from /ccls/src/cache_manager.cc:1:
/ccls/src/cache_manager.h:3:10: fatal error: 'optional' file not found
#include <optional>
^~~~~~~~~~
1 error generated.
CMakeFiles/ccls.dir/build.make:89: recipe for target 'CMakeFiles/ccls.dir/src/cache_manager.cc.o' failed
make[2]: *** [CMakeFiles/ccls.dir/src/cache_manager.cc.o] Error 1
make[2]: Leaving directory '/ccls/release'
CMakeFiles/Makefile2:70: recipe for target 'CMakeFiles/ccls.dir/all' failed
make[1]: *** [CMakeFiles/ccls.dir/all] Error 2
make[1]: Leaving directory '/ccls/release'
Makefile:132: recipe for target 'all' failed
make: *** [all] Error 2
似乎跟 experimental 有关?
optional 是 c++17头文件。ccls 之前用experimental/filesystem, GCC >=5.3 对应的libstdc++才有。后来删除改用llvm/Support/FileSystem.h 了
clang++ -v -xc++ -E /dev/null
找系统头文件搜索路径,看选择的 libstdc++ 路径是否包含 string_view optional variant
不包含 string_view optional variant
:
root@fc44d3fb118c:/# clang++-6.0 -v -xc++ -E /dev/null
clang version 6.0.1-svn331815-1~exp1~20180510083832.81 (branches/release_60)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.3.0
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0
Candidate multilib: .;@m64
Selected multilib: .;@m64
"/usr/lib/llvm-6.0/bin/clang" -cc1 -triple x86_64-pc-linux-gnu -E -disable-free -disable-llvm-verifier -discard-value-names -main-file-name null -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -v -resource-dir /usr/lib/llvm-6.0/lib/clang/6.0.1 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/backward -internal-isystem /usr/include/clang/6.0.1/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-6.0/lib/clang/6.0.1/include -internal-externc-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -fdebug-compilation-dir / -ferror-limit 19 -fmessage-length 272 -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o - -x c++ /dev/null
clang -cc1 version 6.0.1 based upon LLVM 6.0.1 default target x86_64-pc-linux-gnu
ignoring nonexistent directory "/include"
ignoring duplicate directory "/usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0"
ignoring duplicate directory "/usr/include/clang/6.0.1/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0
/usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0
/usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/backward
/usr/include/clang/6.0.1/include
/usr/local/include
/usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0/include
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
# 1 "/dev/null"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 389 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "/dev/null" 2
我知道了。GCC 7 Release Series — Changes, New Features, and Fixes - GNU Project
/usr/include/c++/6/experimental/string_view
/usr/include/c++/7/string_view
/usr/include/c++/7/experimental/string_view
GCC 6帶的libstdc++只能用experimental/string_view
。如果升級的話,用clang++編譯應該就能找到了
我这里一直是:Error from the Language Server: Unable to find file xxx.hpp (Internal Error) [2 times]
测试配置为:
(package-initialize)
(require 'use-package)
(require 'projectile)
(projectile-global-mode)
(require 'company)
(global-company-mode)
(use-package lsp-mode
:ensure t
:commands (lsp-mode)
:diminish (lsp-mode)
:init
(setq lsp-highlight-symbol-at-point nil)
(use-package company-lsp
:ensure t
:commands (company-lsp))
(use-package lsp-ui
:ensure t
:init
(setq lsp-ui-sideline-enable t
lsp-ui-sideline-ignore-duplicate t
lsp-ui-sideline-show-code-actions nil
lsp-ui-sideline-show-flycheck t
lsp-ui-sideline-show-hover nil
lsp-ui-sideline-show-symbol nil
lsp-ui-sideline-delay 1.5
lsp-ui-doc-enable t
lsp-ui-imenu-enable t
lsp-ui-peek-enable t
lsp-ui-flycheck-enable t)
(add-hook 'lsp-mode-hook #'lsp-ui-mode)
:config
(define-key lsp-ui-mode-map [remap xref-find-definitions] #'lsp-ui-peek-find-definitions)
(define-key lsp-ui-mode-map [remap xref-find-references] #'lsp-ui-peek-find-references)))
(use-package ccls
:ensure t
:init
(setq ccls-sem-highlight-method 'nil)
(add-hook 'c++-mode-hook #'lsp-ccls-enable))