vscode配置c++的opencv环境
时间: 2023-11-13 14:57:18 浏览: 127
vscode配置c++环境
好的,以下是配置步骤:
1. 安装 Visual Studio Code 和 C/C++ 扩展
2. 下载 OpenCV 并解压到某个目录下
3. 在 VS Code 中打开一个 C++ 文件,按下 Ctrl + Shift + P,输入 "C/C++: Edit Configurations (JSON)" 并选择它
4. 在打开的 launch.json 文件中添加以下配置:
```
{
"version": "0.2.0",
"configurations": [
{
"name": "g++ - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"preLaunchTask": "C/C++: g++ build active file",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set path to opencv libraries",
"text": "-environment-cd ${workspaceFolder}/opencv/build",
"ignoreFailures": true
},
{
"description": "Set path to opencv libraries",
"text": "-environment LD_LIBRARY_PATH=${workspaceFolder}/opencv/build/lib",
"ignoreFailures": true
}
]
}
]
}
```
5. 在 setupCommands 中添加以下两个命令,以设置 OpenCV 库的路径:
```
{
"description": "Set path to opencv libraries",
"text": "-environment-cd ${workspaceFolder}/opencv/build",
"ignoreFailures": true
},
{
"description": "Set path to opencv libraries",
"text": "-environment LD_LIBRARY_PATH=${workspaceFolder}/opencv/build/lib",
"ignoreFailures": true
}
```
6. 在 VS Code 中打开一个 C++ 文件,按下 F5,选择 "g++ - Build and debug active file",然后按下回车键即可开始调试。
阅读全文