sublimelsp / LSP-clangd

C/C++ support for Sublime's LSP plugin provided through clangd.
MIT License
43 stars 1 forks source link

LSP cannot find opencv headers from msys2 packages #2

Closed sleeplessai closed 1 year ago

sleeplessai commented 1 year ago

I installed LSP and LSP-clangd as instructions both on my Windows and Linux workstations. The one on Linux works well but the other one fails to index because it cannot find opencv headers normally.

On Windows, I manage the environment with Msys2 includes Clang 15.0 compiler. I also installed the packages include the following two:

clang64/mingw-w64-clang-x86_64-opencv 4.6.0-9 [installed] clang64/mingw-w64-clang-x86_64-eigen3 3.4.0-1 [installed]

The eigen3 library and its headers are indexed correctly, LSP-clangd works well on it. I wrote the include syntax like

include <opencv2/opencv.hpp>

The extension raises an error 'opencv2/opencv.hpp' file not found

I generate a copy of compile_commands.json via CMake, but the error remains. I have no idea to solve the problem, please help me, thanks a lot.

rwols commented 1 year ago

What does your compile_commands.json look like, and what is the actual include directory for opencv?

sleeplessai commented 1 year ago

What does your compile_commands.json look like, and what is the actual include directory for opencv? This copy is generated by correct compiling cmake, I put it both in build/ and the project root.

[
{
"directory": "/d/Devel/games101hw/Hw1/hw1/build",
"command": "/clang64/bin/c++.exe -I/usr/local/include -isystem /clang64/include/opencv4 -std=gnu++17 -o CMakeFiles/Rasterizer.dir/main.cpp.o -c /d/Devel/games101hw/Hw1/hw1/main.cpp",
"file": "/d/Devel/games101hw/Hw1/hw1/main.cpp"
},
{
"directory": "/d/Devel/games101hw/Hw1/hw1/build",
"command": "/clang64/bin/c++.exe -I/usr/local/include -isystem /clang64/include/opencv4 -std=gnu++17 -o CMakeFiles/Rasterizer.dir/rasterizer.cpp.o -c /d/Devel/games101hw/Hw1/hw1/rasterizer.cpp",
"file": "/d/Devel/games101hw/Hw1/hw1/rasterizer.cpp"
},
{
"directory": "/d/Devel/games101hw/Hw1/hw1/build",
"command": "/clang64/bin/c++.exe -I/usr/local/include -isystem /clang64/include/opencv4 -std=gnu++17 -o CMakeFiles/Rasterizer.dir/Triangle.cpp.o -c /d/Devel/games101hw/Hw1/hw1/Triangle.cpp",
"file": "/d/Devel/games101hw/Hw1/hw1/Triangle.cpp"
}
]
rwols commented 1 year ago

You seem to have generated the compile_commands.json from a Cygwin or msys2 terminal. This creates Unix paths. Sublime text starts as a windows application and expects windows paths.

sleeplessai commented 1 year ago

You seem to have generated the compile_commands.json from a Cygwin or msys2 terminal. This creates Unix paths. Sublime text starts as a windows application and expects windows paths.

Yes. But the eigen3 can index normally while opencv fails.

LDAP commented 1 year ago

eigen3 isn't even in your compile_commands.json? Maybe try to figure out why that is working, that could explain why opencv isn't. Also make sure that those opencv headers are present where they should.

sleeplessai commented 1 year ago

eigen3 isn't even in your compile_commands.json? Maybe try to figure out why that is working, that could explain why opencv isn't. Also make sure that those opencv headers are present where they should.

Yes, it didn't contain eigen3 in json.

#include <eigen3/Eigen/Eigen>
#include <eigen3/Eigen/Dense>
#include <eigen3/Eigen/src/Core/Matrix.h>
#include <opencv2/opencv.hpp>

That's what I included in the source file. I can go to definition by eigen headers but opencv cannot find.

sleeplessai commented 1 year ago

@rwols @LDAP Good news here. This problem generally occurs on the current latest opencv4. The previous version seems alright. Since the library headers at /clang64/include can be indexed well, I guess the include/ has been indexed but the opencv4 has put itself at the wrong place. What I did to solve this error is copying the whole /clang64/include/opencv4/opencv2 to upper directory /clang64/include/opencv2. Now the extension senses opencv.hpp as expected.