eis3nheim · 2022-02-13 13:12
When I try to include C standard library `#include <stdio.h>` I get an error that it's not found.
How can I solve such a problem?
NoisyFrequency · 2022-02-13 14:08
Do you have this issue with other IDE's? I use LSP-mode with C in Emacs and have no problems
big_lentil · 2022-02-13 14:30
The C standard library is not compiler specific, so including headers from it should work regardless of whatever language server you're using as long as it's properly set up. That being said AFAIK there aren't that many options, and I don't think gcc has a language server yet, so you'll probably have to use clangd for the language server, but you can still compile using gcc.
Do you have clangd installed? It'd also be useful if you posted the relevant parts of your config.
janoc · 2022-02-13 14:42
You certainly can use gcc toolchain with LSP.
However, if you want to use LSP server (regardless of which one) with C/C++ you need to configure it to find where your headers are and which compiler options are in use. That is usually achieved with a compilation database - e.g. `compile-commands.json` (tools like `cmake` or `bear` can generate it for you) or `compile_flags.txt` (for clangd).
This is documented in many tutorials on how to set up Emacs for C/C++, e.g. this one:
https://emacs-lsp.github.io/lsp-mode/tutorials/CPP-guide/
hangingpawns · 2022-02-13 16:38
There isn't a language server for gcc yet. I doubt there will ever be an officially supported one.
You can, however, compile your code with GCC. That isn't a problem.
nononoko · 2022-02-13 17:43
You can look at some of the packages used for the C/C++ layer for doom emacs. That configuration is pretty good.
[deleted] · 2022-02-14 03:53
Yes, I do everyday. Actually, `clangd` and `ccls` both are compiler independent and mostly depends on `compile_commands.json`
holgerschurig · 2022-02-14 08:02
Yes, I regularly compile with GCC, and still use lsp (actually, eglot).
On Debian, you can
apt install bear
or you can get it from https://github.com/rizsotto/Bear. Then you simply do
make clean
bear -- make
and you'll get the `compile_commands.json` file that LSP server (in my case clangd) then uses.
Now, if you use CMake (shudder) or Meson (better) you can let them make the compilation database for you, no need for bear them.
amanol · 2022-02-14 14:47
You can check [here](https://clangd.llvm.org/guides/system-headers) about the system headers, where there are some peculiarities.