我正在使用Visual Studio Code开发C ++项目,并且在自定义位置安装了OpenCV。但是,当我尝试包含OpenCV的头文件时,它抱怨以下错误:
#include检测到错误。考虑更新您的compile_commands.json或includePath。该翻译单元(/home/.../dev/communication-module/modules/.../.../src/....cpp)的花粉被禁用。 C / C ++(1696)
无法打开源文件“ opencv2 / core / mat.hpp” C / C ++(1696)
以下是相同错误的屏幕截图:
我的.vscode/c_cpp_properties.json
文件如下所示:
{
"configurations": [
{
"name": "Linux",
"includePath": [
"/opt/sdk/sysroots/corei7-64-poky-linux/usr/include/opencv2",
"/opt/sdk/sysroots/corei7-64-poky-linux/usr/include/opencv2/core",
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64",
"compileCommands": "${workspaceFolder}/build/compile_commands.json",
"browse": {
"path": [
"/opt/sdk/sysroots/corei7-64-poky-linux/usr/include/opencv2",
"/opt/sdk/sysroots/corei7-64-poky-linux/usr/include/opencv2/core",
"${workspaceFolder}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 4
}
显然mat.hpp
文件在那里:
$ ls /opt/sdk/sysroots/corei7-64-poky-linux/usr/include/opencv2/core | grep mat.hpp
mat.hpp
不过,Visual Studio Code不会将其拾取。这是为什么?对于Visual Studio Code,我还应该更改什么才能找到我的OpenCV头文件?
答案 0 :(得分:0)
您的包含路径/opt/sdk/sysroots/corei7-64-poky-linux/usr/include/opencv2
应该以{{1}}结尾。
当您输入/include
时,编译器将搜索尝试#include <opencv2/core/mat.hpp>
的方法,显然不起作用。
答案 1 :(得分:0)
违规行显然是:
"compileCommands": "${workspaceFolder}/build/compile_commands.json",
删除后,现在可以使用了。我的c_cpp_properties.json
配置现在如下所示:
{
"configurations": [
{
"name": "Linux",
"includePath": [
"/opt/sdk/sysroots/corei7-64-poky-linux/usr/include",
"${workspaceFolder}/**"
],
"defines": [],
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}