[英]OpenCV cannot open video file when run with Visual Studio 2015
[英]Visual Studio Code “cannot open source file” error when including OpenCV
我正在使用 Visual Studio Code 開發 C++ 項目,並且在自定義位置安裝了 OpenCV。 但是,當我嘗試從 OpenCV 中包含 header 文件時,它會抱怨以下錯誤:
#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 並沒有接受它。 這是為什么? 為了找到我的 OpenCV header 文件,我還應該對 Visual Studio Code 進行哪些更改?
違規行顯然是:
"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
}
您的包含路徑/opt/sdk/sysroots/corei7-64-poky-linux/usr/include/opencv2
應該以/include
結尾。
當您鍵入#include <opencv2/core/mat.hpp>
時,編譯器將搜索 try out /opt/sdk/sysroots/corei7-64-poky-linux/usr/include/opencv2/opencv2/core/mat.hpp
這將顯然行不通。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.