相关名词就不解释了,这里主要讲讲在vscode里怎么配,这里假设大家相关工具已经装好。
1、在.vscode目录下,新建以下几个配置文件,当然也可以通过vscode命令自动生成,如果你已有这些文件直接修改即可。
c_cpp_properties.json(代码提示):
{ "configurations": [ { "name": "Win32", "windowsSdkVersion": "10.0.18362.0", "compilerPath": "${env:MSYS2}/mingw64/bin/gcc", "includePath": ["${env:MSYS2}/mingw64/include"], "defines": ["_DEBUG", "UNICODE", "_UNICODE"], "intelliSenseMode": "gcc-x64" } ], "version": 4 }
tasks.json(编译):
{ "tasks": [ { "type": "shell", // 标示名 "label": "build", // 要执行的命令,这里用了一个bat脚本来构建 "command": "./build.sh", // 命令参数 "args": ["${fileBasename}", "${fileBasenameNoExtension}.exe"], "group": { "kind": "build", "isDefault": true }, "problemMatcher": "$gcc" } ], "version": "2.0.0" }
launch.json(调试):
{ // 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。 // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "gdb", "type": "cppdbg", "request": "launch", // 要调试的程序 "program": "${workspaceFolder}/build/${fileBasenameNoExtension}.exe", // 程序运行参数 "args": ["./video/sample.mp4"], // 是否在入口自动断点 "stopAtEntry": false, // 工作目录 "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "MIMode": "gdb", "miDebuggerPath": "gdb.exe", // 先编译,再调试,对应tasks.json中的标示 "preLaunchTask": "build", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } ] }
settings.json(vscode终端配置):
{ "editor.formatOnSave": true, // 要使用cmd终端,其他终端会有兼容问题 "terminal.integrated.shell.windows": "${env:MSYS2}/usr/bin/bash.exe", "terminal.integrated.shellArgs.windows": ["--login"], "terminal.integrated.env.windows": { "MSYSTEM": "MINGW64", "CONTITLE": "MinGW x64", "C_INCLUDE_PATH": "/mingw64/include", "CPLUS_INCLUDE_PATH": "/mingw64/include" } }
2、在根目录下创建构建脚本,构建脚本主要是配置msvc环境,配置cl.exe的构建参数(头文件、链接库等)
build.bat(构建脚本,可根据需要自行更改):
#!/bin/sh # 创建build目录 if [ ! -d "build" ]; then mkdir build fi gcc $1 -g -o build/$2 -lavformat -lavcodec -lavutil -lSDl2main -lSDL2