Suppose i have a project with and src folder to keep all my code, and an include folder to store third-party libraries.
Let's say there is a file include/TestLib/lib.hpp with the following code:
// lib.hpp
#include <string>
#include <iostream>
void Log(std::string text){
std::cout << text << std::endl;
}
and the other file is src/main.cpp:
#include "../include/TestLib/lib.hpp"
int main(){
Log("Hello world");
}
In order for it to not give errors on neovim i have to use the full path of all hpp files. Premake allows me to use include directories to avoid using that and only needing to do as follows:
#include "lib.hpp"
int main(){
Log("Hello world");
}
When i build it, it compiles correctly, however neovim/clangd is not able to find the include directories. How can i tell clangd where to look for those files?
Suppose i have a project with and src folder to keep all my code, and an include folder to store third-party libraries.
Let's say there is a file include/TestLib/lib.hpp with the following code:
// lib.hpp
#include <string>
#include <iostream>
void Log(std::string text){
std::cout << text << std::endl;
}
and the other file is src/main.cpp:
#include "../include/TestLib/lib.hpp"
int main(){
Log("Hello world");
}
In order for it to not give errors on neovim i have to use the full path of all hpp files. Premake allows me to use include directories to avoid using that and only needing to do as follows:
#include "lib.hpp"
int main(){
Log("Hello world");
}
When i build it, it compiles correctly, however neovim/clangd is not able to find the include directories. How can i tell clangd where to look for those files?
Share Improve this question asked Mar 30 at 5:16 DSlowerDSlower 211 silver badge6 bronze badges 2- 1 What build system are you using? Cmake? Try generating compile_commands.json, most LSPs use that and Neovim appears to look for it in project root and build/ directory – Dominik Kaszewski Commented Mar 30 at 7:08
- @DominikKaszewski When i generate a make project, premake don't generate the compile_commands.json file, however, when i generate a codelite project and compile it with it, codelite does give me the file. The solution was to use codelite first, then deleting the codelite related files and leave the compile_commands.json file, after that it works on neovim without showing errors. Thanks! – DSlower Commented Mar 30 at 15:07
1 Answer
Reset to default 2For anyone with the same problem, you just need the compile_commands.json file on the root of the project. Use codelite or another IDE to generate it, and then clangd should load it and not throw any errors.