Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compile commands is not working in lsp-mode(ccls) #50

Closed
lucaspeixotot opened this issue Jul 6, 2019 · 2 comments
Closed

compile commands is not working in lsp-mode(ccls) #50

lucaspeixotot opened this issue Jul 6, 2019 · 2 comments
Labels
question Further information is requested

Comments

@lucaspeixotot
Copy link

Hello, I'm trying to use for the first time lsp-mode for my C/C++ projects. This is my minimal(I think) configuration for this.

2019-07-06-001628_448x629_scrot
2019-07-06-001638_388x112_scrot

When I did open the first project some functions definitions were being recognized and etc, but I was with a problem related to some libraries that were not being found. In order to solve this I read this link https://github.com/MaskRay/ccls/wiki/lsp-mode and compiled my project to generate the compile_commands.json. After that, everything seems don't work, flycheck, autocomplete and etc, and this msg(LSP :: not indexed) is being shown in every line.

2019-07-06-002338_492x453_scrot

How can I solve this and make lsp-mode work for me? Do I need to write something else in my config file? Just to be clear, I generated compile_commands.json with mkdir build && cd build && cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=YES .. && ln -s compile_commands.json.

I posted this in reddit and the people tell me that the problem was with ccls and I should ask here what can be happening.

@MaskRay
Copy link
Member

MaskRay commented Jul 8, 2019

2019-07-06-001628_448x629_scrot
2019-07-06-001638_388x112_scrot

Please paste text, not images.

mkdir build && cd build && cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=YES .. && ln -s compile_commands.json

Tip:

cmake -H. -Bbuild -DCMAKE_EXPORT_COMPILE_COMMANDS=ON

to avoid cd

Here are some things you should try before filing a bug report:

If none of those help, remove this section and fill out the four sections in the template below.


Observed behavior

Describe what happened. Any aids you can include (that you think could be relevant) are a tremendous help.

  • compile_commands.json or .ccls (wiki/Project-Setup)
  • Reduce to A minimal set of .c .cc .h .hh files that can still demonstrate the issue.
  • Consider a screencast gif.

Expected behavior

Describe what you expected to happen.

Steps to reproduce

  1. Select these example steps,
  2. Delete them,
  3. And replace them with precise steps to reproduce your issue.

System information

  • ccls version (git describe --tags --long):
  • clang version:
  • OS:
  • Editor:
  • Language client (and version):

@MaskRay MaskRay closed this as completed Sep 27, 2019
@MaskRay MaskRay added the question Further information is requested label Sep 27, 2019
@cosven
Copy link

cosven commented May 7, 2020

I've met the exact same phenomenon, and I solved it by adjusting the compiler flags.

TL;DR, I find the lsp server will work as long as the project can be built with clang(note: working with gcc does not state that the project will work with clang).


long long story below

I record my experience here in case people may meet the same problem. Note, I'm new to c++ and c++ build system.

My System Environment

I have a system(centos 7.6), which installed devtoolset-7(gcc 7).
I also compile and install clang 11 by myself.

My Project Info

I try to use ccls on https://github.com/tikv/titan project.

After I run

cmake -H. -Bbuild -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
ln -sf build/compile_commands.json .

I can see the compiler_commands.json, and the first several lines looks like this

☁ ~/p/titan master* > head -6 compile_commands.json
[
{
  "directory": "/root/xxx/titan/build",
  "command": "/opt/rh/devtoolset-7/root/usr/bin/c++  .............. -W -Wextra -Wall -Wsign-compare -Wshadow -Wno-unused-parameter -Wno-unused-variable -Woverloaded-virtual -Wnon-virtual-dtor -Wno-missing-field-initializers -Wno-strict-aliasing -std=c++11 -fno-omit-frame-pointer -momit-leaf-frame-pointer -march=native -Werror -fno-builtin-memcmp   -o CMakeFiles/titan_blob_file_iterator_test.dir/src/blob_file_iterator_test.cc.o -c /root/xxx/titan/src/blob_file_iterator_test.cc",
  "file": "/root/xxx/titan/src/blob_file_iterator_test.cc"
},

And I try to start my Emacs and open the project, but it does not work, and the lsp server(ccls) always responds with not indexed. And if I remove the compiler_commands.json, it works partially(some header file can't be found by lsp server).

I'm pretty sure that there are some problems in my json file, however, I do not know where the problem is (I think the root cause is that I do not know the working mechanism of ccls and I have little knowledge about c++).

After long time searching, I decide to try clangd to see if it can work properly, but of course, it failed. And the error message I found from the clangd:: stderr is Couldn't build compiler instance.

I search the error message in clangd source code and I found the reason this happens is that the compiler should be clang instead of gcc. So I disable my gcc and try to re-build my project with clang, to my surprise, the build-process failed. After some investigation, I adjust some compile flags and the project can be built with clang.

cmake -H. -Bbuild -DCMAKE_EXPORT_COMPILE_COMMANDS=ON  -DPORTABLE=1

After that, the lsp server also works 🙈.

I change the lsp server from clangd to ccls, and it also works well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants