适用于Windows和MSVC的ccls编译简明指南

cclsMaskRay编写的一款适用于C/C++/OC的LSP实现。在此基础上,他还针对VSCode编写了对应的插件,用以为这些语言提供编辑器的自动完成、语法提示和错误检查功能。在这篇帖子中,我打算简要总结一下如何在Windows下编译ccls。毕竟这也是各位在VSCode中使用ccls插件的第一步。

首先,我们需要注意到,ccls需要使用Clang生成的语法树来对文件进行分析,而不幸的是,在官网下载到的LLVM+Clang安装程序中是没有这部分功能所对应的头文件的。例如,在MaskRay/ccls/src/indexer.cc中有以下包含指令:

#include <clang/AST/AST.h>
#include <clang/Frontend/FrontendAction.h>
#include <clang/Index/IndexDataConsumer.h>
#include <clang/Index/IndexingAction.h>
#include <clang/Index/USRGeneration.h>
#include <clang/Lex/PreprocessorOptions.h>
#include <llvm/ADT/DenseSet.h>
#include <llvm/Support/CrashRecoveryContext.h>
#include <llvm/Support/Path.h>

The Windows prebuilt binaries lack C++ header files, thus they cannot be used.

如果你的LLVM中提供的包含路径下没有这些头文件,不妨先在本地编译一下LLVM+Clang

随后便可以正式开始ccls的编译工作了。先准备好存储库

PS G:\> git clone https://github.com/MaskRay/ccls --depth 2
Cloning into 'ccls'...
remote: Enumerating objects: 234, done.
remote: Counting objects: 100% (234/234), done.
remote: Compressing objects: 100% (184/184), done.
Receiving objects: 100% (234/234), 216.44 KiB | 814.00 KiB/s, done.eceiving objects:  99% (232/234)

Resolving deltas: 100% (123/123), done.
PS G:\> cd ccls
PS G:\ccls> git submodule init
Submodule 'third_party/rapidjson' (https://github.com/Tencent/rapidjson) registered for path 'third_party/rapidjson'
PS G:\ccls> git submodule update
Cloning into 'G:/ccls/third_party/rapidjson'...
Submodule path 'third_party/rapidjson': checked out '6a905f9311f82d306da77bd963ec5aa5da07da9c'

然后打开cmake-gui,填写源代码位置和build文件夹路径,点击“Configure”。使用默认值确认即可。

如果你的LLVM没有放在默认路径下(C:\Program Files\LLVM),则在Configure之前需要点击“Add Entry”,增加一项 CMAKE_PREFIX_PATH ,指定你的LLVM安装路径。

点击“Generate”,生成VS解决方案。点击“Open Project”,随后的操作就比较直观了。选择生成配置(Debug / RelWithDebInfo),然后编译ccls项目。

编译成功后,在输出目录下便可以找到ccls.exe了。之后只需要在VSCode的ccls插件配置下指定这个路径即可。

 

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

ERROR: si-captcha.php plugin: GD image support not detected in PHP!

Contact your web host and ask them to enable GD image support for PHP.

ERROR: si-captcha.php plugin: imagepng function not detected in PHP!

Contact your web host and ask them to enable imagepng for PHP.

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据

Content is available under CC BY-SA 3.0 unless otherwise noted.