小白编译 ccls 不通过,感觉脑壳疼


#1

本人用 ubuntu16.04和win10下都不能编译成功。 1.win10下用msys2根据` git clone https://git.llvm.org/git/llvm.git git clone https://git.llvm.org/git/clang.git llvm/tools/clang

cd llvm

cmake -H. -BRelease -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=cl -DCMAKE_CXX_COMPILER=cl -DLLVM_TARGETS_TO_BUILD=X86 ninja -C Release clangFormat clangFrontendTool clangIndex clangTooling clang`

编译好 clang+llvm后编译ccls报错 $ cmake -H. -BRelease -G Ninja -DCMAKE_CXX_FLAGS=-D__STDC_FORMAT_MACROS

– The CXX compiler identification is Clang 9.0.0 – Check for working CXX compiler: F:/llvm/Release/bin/clang-cl.exe – Check for working CXX compiler: F:/llvm/Release/bin/clang-cl.exe – broken CMake Error at D:/msys64/mingw64/share/cmake-3.11/Modules/CMakeTestCXXCompiler.cmake:45 (message): The C++ compiler

"F:/llvm/Release/bin/clang-cl.exe"

is not able to compile a simple test program.

It fails with the following output:

Change Dir: F:/ccls/Release/CMakeFiles/CMakeTmp

Run Build Command:"D:/msys64/mingw64/bin/ninja.exe" "cmTC_beac8"
[1/2] Building CXX object CMakeFiles\cmTC_beac8.dir\testCXXCompiler.cxx.obj
[2/2] Linking CXX executable cmTC_beac8.exe
FAILED: cmTC_beac8.exe
cmd.exe /C "cd . && D:\msys64\mingw64\bin\cmake.exe -E vs_link_exe --intdir=CMakeFiles\cmTC_beac8.dir --manifests  -- D:\msys64\usr\bin\link.exe /nologo CMakeFiles\cmTC_beac8.dir\testCXXCompiler.cxx.obj  /out:cmTC_beac8.exe /implib:cmTC_beac8.lib /pdb:cmTC_beac8.pdb /version:0.0  /machine:x64  /debug /INCREMENTAL /subsystem:console  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
RC Pass 1: command "rc /foCMakeFiles\cmTC_beac8.dir/manifest.res CMakeFiles\cmTC_beac8.dir/manifest.rc" failed (exit code 0) with the following output:
绯荤粺鎵句笉鍒版寚瀹氱殑鏂囦欢銆?
ninja: build stopped: subcommand failed.

CMake will not be able to correctly generate this project. Call Stack (most recent call first): CMakeLists.txt:2 (project)

– Configuring incomplete, errors occurred! See also “F:/ccls/Release/CMakeFiles/CMakeOutput.log”. See also “F:/ccls/Release/CMakeFiles/CMakeError.log”.

2.在ubuntu下直接 wget -c http://releases.llvm.org/7.0.1/clang+llvm-7.0.1-x86_64-linux-gnu-ubuntu-16.04.tar.xz tar xf clang+llvm-7.0.1-x86_64-linux-gnu-ubuntu-16.04.tar.xz cmake -H. -BRelease -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=$PWD/clang+llvm-7.0.1-x86_64-linux-gnu-ubuntu-16.04

报错: cmake -H. -BRelease -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=$PWD/clang+llvm-7.0.1-x86_64-linux-gnu-ubuntu-16.04 CMake Error at CMakeLists.txt:137 (message): Error retrieving Clang resource directory with Clang executable. Output:

/home/sniper/ccls/clang+llvm-7.0.1-x86_64-linux-gnu-ubuntu-16.04/bin/clang: 5: /home/sniper/ccls/clang+llvm-7.0.1-x86_64-linux-gnu-ubuntu-16.04/bin/clang: Syntax error: “(” unexpected

– Configuring incomplete, errors occurred! See also “/home/sniper/ccls/Release/CMakeFiles/CMakeOutput.log”. See also “/home/sniper/ccls/Release/CMakeFiles/CMakeError.log”.

有人可以指导一下吗? 有傻瓜式的指令操作吗?


#2

留邮箱,我给你一个


#3

e190@163.com 加Q也可以 839281922 谢谢 大神


#4

LZ看过我之前发的这个帖子吗?( 求助:ccls的编译问题,链接不通过 ) 16.04需要加ppa源装libstdc++-7-dev

我最近刚重装过一次16.04,官网上的步骤是没有问题的,我一周前刚成功编译过


#5

我看了你的那个帖子,感觉你是不是修改了 CMakeLists.txt?还是有点懵,可以简单说下你的步骤吗?


#6

不用修改。那是我一开始没装libstdc++-7-dev时各种瞎试留下的东西。

16.04上步骤应该很简单:

  1. 添加ppa源ppa:ubuntu-toolchain-r/test
  2. 安装libstdc++-7-dev
  3. 按照宋教授的Wiki上两个cmake的命令撸一遍就行了

我这几周在两个16.04的环境上编译都成功了,一个环境乱七八糟,另一个是重装后全新的16.04,都是没有问题的。用的就是你试的16.04 prebuilt的clang+LLVM,你再试试吧


#7

环境都装好了呀,还是出现这种错误是为什么啊? 感觉是下载的llvm+clang不能用,但是不知道怎么办


#8

好奇怪,我没见过这种错。

要不然你试试这个:

  1. 把下载的clang+LLVM的bin加到$PATH的开头
  2. 改运行CXX=clang++ cmake ......试试

哦对,记得把Release文件夹删掉再试

BTW,我也是小白,所以原理什么的我都不太懂哈 :sweat_smile:


#9

还是不行,我到clang的目录下执行 clang -v,都没作用。 1554708262(1)

把clang+LLVM的bin 添加到 环境变量,也是找不到clang. 这就很头痛了:sob:


#10

… 这个就很脑阔疼了。。。 :disappointed_relieved:

重新下一遍clang? 你这个错误已经超纲了。。。


#11

已发送到你邮箱,不过我是windows平台的


#12

谢谢了。这个直接就可以用吗?你没用msys2 编译吗?


#13

都用过,但是2017编译的更好用。如果你自己的项目是用vs编译的话,msys编译的兼容性不好,各种不补全。vs还可以装一个插件,可以生成compile_commands.json,配合ccls,完美


#14

大神可以给我也发一个么?谢谢。邮箱fcangss@126.com


#15

Linux 和 Windows(WSL) 下也可以试试 Homebrew:


#16

可以,不过我是windows


#17

我也是win的,正好正好,非常感谢


#18

docker run -it --name ccls-build ubuntu:18.04 /bin/bash

apt install -y git gcc cmake clang-8 libclang-8-dev llvm-8 llvm-8-dev zlib1g-dev libncurses-dev

git clone --depth=1 --recursive https://github.com/MaskRay/ccls

cd ccls

cmake -H. -BRelease -DCMAKE_BUILD_TYPE=Release

cmake --build Release --target install

我是这么编译的,发现clang使用clang-8编译更省事


#20

能发我一个Ubuntu16.04的嘛? 我编译的错误提示: In file included from /home/ubuntu/conf/ccls/src/position.hh:18:0, from /home/ubuntu/conf/ccls/src/clang_tu.hh:18, from /home/ubuntu/conf/ccls/src/clang_tu.cc:16: /home/ubuntu/conf/ccls/src/utils.hh:18:20: fatal error: optional: No such file or directory compilation terminated. CMakeFiles/ccls.dir/build.make:75: recipe for target ‘CMakeFiles/ccls.dir/src/clang_tu.cc.o’ failed make[2]: *** [CMakeFiles/ccls.dir/src/clang_tu.cc.o] Error 1 CMakeFiles/Makefile2:136: recipe for target ‘CMakeFiles/ccls.dir/all’ failed make[1]: *** [CMakeFiles/ccls.dir/all] Error 2 Makefile:129: recipe for target ‘all’ failed make: *** [all] Error 2


#21

ubuntu 16.04 里software center里有ccls,可直接安装

其实也就是snap install ccls --classic