admin管理员组文章数量:1356889
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.
本文标签: headerHow to get include directories working for c projects on neovimStack Overflow
版权声明:本文标题:header - How to get include directories working for c++ projects on neovim - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743996073a2573011.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论