Configuración correcta de Ubuntu18.04 VScode (c ++) (prueba de cámara opencv)

Lo que hay que preparar: vscode vscode-c ++ entorno de compilación opencv, principalmente para modificar tres documentos, launch.json, c_cpp_properties.json, task, json
vscode configuration C ++ tutoriales en Internet, no los repetiré aquí.
La estructura actual de mi archivo es la siguiente:

1. Cree un nuevo archivo cpp y guárdelo.
2. El botón de depuración (pequeño error) en el lado izquierdo de vscode-Debug -> Open Configurations -> Open the option box -> C ++ (GDB / LLDB) -> g ++ build and debug active file
3. Regrese a el explorador (izquierda (El primer icono en la barra lateral)Inserte la descripción de la imagen aquí

4 Después de las operaciones anteriores, abra el archivo launch.json y modifíquelo para:

{
    
    
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
    
    
            "name": "(gdb) Launch", /* 配置名称,将会在启动配置的下拉菜单中显示 */
            "preLaunchTask": "build", /* 调试前执行 'build'选项 */
	    //"preLaunchTask": "g++", /* 调试会话开始前执行的任务,一般为编译程序,c++为g++, c为gcc */
            "type": "cppdbg", /* 配置类型,这里只能为cppdbg */
            "request": "launch",/**/
            "program": "${workspaceFolder}/main.o", /*选择要调试的文件路径*/
            "args": [], /* 程序调试时传递给程序的命令行参数,一般设为空即可  */
            "stopAtEntry": false,/* 设为true时程序将暂停在程序入口处,一般设置为false */
            "cwd": "${workspaceFolder}", /* 调试程序时的工作目录,一般为${workspaceFolder}即代码所在目录 */
            "environment": [],
            "externalConsole": false, /* 调试时是否显示控制台窗口,一般设置为true显示控制台 */
            "MIMode": "gdb",
           
            "setupCommands": [
                {
    
    
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

5. Configure task.json

{
    
    
	"version": "2.0.0",
	"tasks": [
		{
    
    
			"type": "shell",	/* 定义任务是被作为进程运行还是在 shell 中作为命令运行,默认是shell,即是在终端中运行,因为终端执行的就是shell的脚本 */
			"label": "build",	/* 要与launch.json文件里的preLaunchTask的内容保持一致 */
			"command": "/usr/bin/g++",	/* 这里填写你的编译器地址 */
			"args": [
				/* 类似与qt的Pro文件里开始的那几句 */
				"-std=c++11",// 静态链接
                "-static-libgcc",
				"-Wall",// 开启额外警告
				
				/* 说明整个项目所需的头文件路径(.h)*/
				"-I","${workspaceFolder}/",
                "-I","/usr/local/include/",
                "-I","/usr/local/include/opencv4/",
                "-I","/usr/local/include/opencv4/opencv2/",
				
				/* 说明整个项目所需的源文件路径(.cpp) */
				"-g",	
                "${workspaceFolder}/main.cpp",/* ${workspaceFolder}表示路径从当前项目文件夹开始 */

				"-o",	/* 编译输出文件的存放路径 */
				"${fileBasenameNoExtension}.o", /* 要与launch.json文件里的program的内容保持一致 */
				/* ${fileDirname} 是指 文件目录名 相当于${workspaceFolder}*/
				/* ${fileBasenameNoExtension}意思是指 该路径下没有扩展名的文件基本名称没有扩展名 */ 
				/* 也可以这样:"${workspaceFolder}/run.o", */

				/* OpenCV的lib库 */
				"/usr/local/lib/libopencv_*",
			],
			"options": {
    
    
				"cwd": "${workspaceFolder}"	/* 调试程序时的工作目录,一般为${workspaceFolder}即代码所在目录 */
			},
			"problemMatcher": [
				"$gcc"	/* 要使用的问题匹配程序。 */
			],
			"group": "build" /* 将任务标记为可通过 "运行生成任务" 命令访问的生成任务。*/
		}
	]
}

6, Ctrl + Shift + P para abrir el cuadro de búsqueda, escriba c ++, habrá proyectos alternativos, seleccione el icono Editar configuraciones (JSON)
y modifique c_cpp_properties.json para:

{
    
    
    "configurations": [
        {
    
    
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/usr/local/include/",
                "/usr/local/include/opencv4/",
                "/usr/local/include/opencv4/opencv2/"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c11",
            "cppStandard": "c++14",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}

El directorio donde está instalado opencv debe estar en / usr / local / include.
Puede ingresar el comando:

cd /usr/local/include
ls

Los resultados son los siguientes:
Inserte la descripción de la imagen aquí

7. De vuelta al archivo de prueba, F5 ejecuta el siguiente
programa de prueba:

#include <iostream>
#include<opencv2/opencv.hpp>
#include<opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
int main() 
{
    
    
    cout<<"hello world"<<endl;
    VideoCapture capture(0);
    while (1)
    {
    
    
        Mat frame;
        capture>>frame;
        imshow("src",frame);
        waitKey(27);
    }
}

Supongo que te gusta

Origin blog.csdn.net/Msyusheng/article/details/110288133
Recomendado
Clasificación