Search code examples
c++qt5neovim

Problem with Qt5 libs in nvim with clangd lsp-server


I am a University student and I have been assigned a project to do in Qt5 and g++11 as the compiler, I use nvim with clangd as the lsp-server. The problem is that the lsb server does not find the various Qt libraries even if installed.

enter image description here

Searching on the internet they said to try adding the libraries to the CPATH, once done however the problem was not solved but resulted in other errors:

enter image description here

With another search I found out that I have to use a build system, something I have never done and searching on the internet I can't understand how to do it, and modify a .json configuration file inside the build folder. The point is that my project folder is this

prog/ -Makefile -main.cpp -prog.pro

In practice, I would be very grateful if someone could explain the problem well to me and help me solve it, as searching on the internet and reading the various documentation I did not understand what I should do.


Solution

  • First of all, to use clangd (or any other compiler) with lsp you need to have a working make file for your project. This can then be converted into a lsp-server configuration. Assuming you use cmake, you can call cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 which will generate a json file containing your lsp-server configuration. In this file, clangd will find all the necessary information where to find the include files (that is currently your problem) and where to find which libraries (this will be the next issue you will stumble into).

    To be honest: At the moment, you are trying to learn C++ alongside with a new environment (Qt), creating build files and configuring a server all at once. All this would even be an issue for an experienced programmer - which you are not.

    So I would recommend installing Qt with the native Qt IDE (called Qt Creator). This IDE will setup a cmake file and a debugging environment for you. Once your program runs nicely, you can then switch to lsp-server environment as a last final step.