Visual Studio 开发(一):安装配置Visual Studio Code
一、为何使用Visual Studio Code
Visual Studio Code作为一个微软发布的轻量级的编辑器,编写和调试C代码是相当方便的,所以推荐使用Visual Studio Code。
二、安装配置Visual Studio Code
下载地址:https://code.visualstudio.com/
下载后,安装,启动后,添加如下的插件:
但是,真正开发的话,只是添加这些插件,还是不够的,还需要安装和配置MinGW环境。
安装完成后,基本的目录结构如下,这里我安装的是 i686-w64-mingw32 版本的mingw32.
后续我们就需要在Visual Studio Code 配置一下环境依赖了,具体如下:
launch.json
{ "version": "0.2.0", "configurations": [ { "name": "g++.exe - 生成和调试活动文件", "type": "cppdbg", "request": "launch", "program": "${fileDirname}\\${fileBasenameNoExtension}.exe", "args": [], "stopAtEntry": false, "cwd": "C:\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin", "environment": [], "externalConsole": true, "MIMode": "gdb", "miDebuggerPath": "C:\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\gdb.exe", "setupCommands": [ { "description": "为 gdb 启用整齐打印", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "C/C++: g++.exe 生成活动文件" } ] }
tasks.json
{ "tasks": [ { "type": "cppbuild", "label": "C/C++: g++.exe 生成活动文件", "command": "C:\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\g++.exe", "args": [ "-g", "${file}", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe", "-lmingw32" ], "options": { "cwd": "C:\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin" }, "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": true }, "detail": "调试器生成的任务。" } ], "version": "2.0.0" }
这时我们将Visual Studio Code重启一下,然后简单的编写一个C语言的Hello World 调试运行一下。查看到输出,那就说明我们成功的配置好的Visual Studio Code了。接下来我们就可以使用C和C++进行代码的编写和调试了。
三、Visual Studio Code 配置SDL2和FFmpeg 开发环境
配置 SDL2
下载SDL2-2.0.14,然后将 i686-w64-mingw32(因为本人的mingw使用的也是i686版本)里面 文件夹中 的文件拷贝到 mingw32 的目录下:
然后再修改tasks.json文件:
{ "tasks": [ { "type": "cppbuild", "label": "C/C++: g++.exe 生成活动文件", "command": "C:\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\g++.exe", "args": [ "-g", "${file}", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe", "-lmingw32", "-lSDL2main", "-lSDL2" ], "options": { "cwd": "C:\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin" }, "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": true }, "detail": "调试器生成的任务。" } ], "version": "2.0.0" }
配置FFmpeg,同SDL,也是将相应的include文件、lib文件、dll文件拷贝到 mingw32中相应的目录中,然后修改tasks.json文件:
{ "tasks": [ { "type": "cppbuild", "label": "C/C++: g++.exe 生成活动文件", "command": "C:\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\g++.exe", "args": [ "-g", "${file}", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe", "-lmingw32", "-lavutil", //(此处为示例引入) //"根据需要引入的依赖,添加相应的lib库" ], "options": { "cwd": "C:\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin" }, "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": true }, "detail": "调试器生成的任务。" } ], "version": "2.0.0" }