Today I did two things:

  • I upgraded some emacs packages (don't know which ones)
  • I installed in addition to emacs 27.1, emacs 28 with native compilation

I built the "gccemacs" in a separate folder but started with the same config I use for emacs 27. But then I realized, lsp-mode (I am using it with ccls) does not recognize libraries like iostream or cstdint. So I wanted to use emacs 27.1 again but emacs 27.1 shows now the same behavior. Things like lsp-diagnose look fine. When I switch to a new project the echo area shows LSP :: CCLS:XXXX initialized successfully

Now when installing gccmacs I also installed gcc-9 and g++-9 and used the following commands:

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 90 --slave /usr/bin/g++ g++ /usr/bin/g++-9 --slave /usr/bin/gcov gcov /usr/bin/gcov-9
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 70 --slave /usr/bin/g++ g++ /usr/bin/g++-7 --slave /usr/bin/gcov gcov /usr/bin/gcov-7

What weird is, is that I can use lsp-find-definition for libraries that get included via the compiler flags like e.g. armadillo library. If I use the command, I jump to /usr/include/armadillo but iostream or cmath can not be found. So this shows at least some minimal amount of functionality is there. Everything else looks fine, I don't get errors only a couple of warnings from other packages after the first byte compilations but that was the case before and it did work this morning. For some reason lsp-mode is not recognizing the standard library. Maybe I setup the new compiler version wrong? I switched back to gcc-7 anyways and gcc --version also tells that this is the case (same with g++). And yes, I can compile my programs and I use bear to execute a make file and generate the necessary .json file. Any ideas of what could be the cause of this issue?

EDIT1: Ok, some times when moving around in the buffer I get the echo message LSP :: Error from Language Server: not indexed (Invalid Request) I think this error also showed when it was working, but just in case.

EDIT2: I commented everything ccls related and used clangd instead but the issue persists. I then delete my .emacs.d folder and installed all packages from scratch with lsp-mode using only melpa-stable but the issue persists.

EDIT 3: I think I have come closer to a solution. It seems like lsp-mode or ccls/clangd does not recognize that I want to code c++ but c. I can include math.h but not cmath (without an error). Same behavior with iostream and stdio.h can I somehow tell lsp-mode to recognize c++?

EDIT 4: In the ccls faq is written, that the header file issue might occur if you e.g. have installed gcc-9 but not g++-9. But for me this is not the case. I have installed gcc-9, g++-9 and libstdc++-9 is installed as well. What I also realized is, that I can do: include <c++/7/iostream> without error because g++-7 is installed. Unfortunately, the ccls or lsp-mode does still complain about std:: (undeclared identifiert).

  • This doesn't sound like an Emacs problem. With lsp-mode, these types of queries are answered by a server program which is external to Emacs. You need to figure out how to configure that program correctly. – db48x Oct 13 '20 at 23:40

I solved the issue. It was not an emacs-ccls or lsp-mode issue but a clang issue. The issue started when I installed gcc-9 on Ubuntu-18.04 using the toolchain-r/test repo:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test

I also noticed that I could not even compile a simple hello-world program using clang++. When compiling with the -v invocation it turned out that clang was looking for gcc-10 even though it was not installed:

Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/10

Installing libstdc++-10 solved the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.