VSCode配置C环境(MinGW)啰里啰唆篇

新建一个文件夹,防止环境污染
https://code.visualstudio.com/docs/cpp/config-mingw参考文章放上。


可以看到自己已经完成了一部分的工作

F12打开我们的头文件



#include <iostream>#include <vector>#include <string>
using namespace std;
int main(){ vector<string> msg{"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"};
for (const string &word : msg) { cout << word << " "; } cout << endl;}


任务的作用是将源文件编译为可执行的文件


我们先看这里
该command设置指定要运行的程序;在这种情况下是g ++。
该args数组指定将传递给g ++的命令行参数。必须按照编译器期望的顺序指定这些参数。
此任务告诉g ++获取活动文件(${file}),对其进行编译,然后在当前目录(${fileDirname})中创建一个与活动文件同名但.exe扩展名为(${fileBasenameNoExtension}.exe)的可执行文件。
https://code.visualstudio.com/docs/editor/variables-reference这里插一个有趣的东西,或者我觉得很有趣的东西。就是这些个变量的意思

好好看看哦

运行

但是出现错误



这样就成功了
{ "version": "2.0.0", "tasks": [ { "type": "cppbuild", "label": "C/C++: g++.exe 生成活动文件", "command": "C:\\MinGW\\bin\\g++.exe", "args": [ "-g", "${file}", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe" ], "options": { "cwd": "C:\\MinGW\\bin" }, "problemMatcher": [ "$gcc" ], "group": "build", "detail": "编译器: C:\\MinGW\\bin\\g++.exe" }, { "type": "cppbuild", "label": "C/C++: gcc.exe 生成活动文件", "command": "C:\\MinGW\\bin\\gcc.exe", "args": [ "-g", "${file}", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe" ], "options": { "cwd": "C:\\MinGW\\bin" }, "problemMatcher": [ "$gcc" ], "group": "build", "detail": "编译器: C:\\MinGW\\bin\\gcc.exe" } ]}
然后也可以构建,C的app

执行也没有错误

Ctrl+Shift+B,会选择要构建的任务



{ "version": "0.2.0", "configurations": [ { "name": "g++.exe - Build and debug active file", "type": "cppdbg", "request": "launch", "program": "${fileDirname}\\${fileBasenameNoExtension}.exe", // 要调试的程序,活动文件夹,和.exe扩展名字的活动文件名字 "args": [], "stopAtEntry": false, // 这个把。。。。就是一启动以后在main处卡死 "cwd": "${workspaceFolder}", "environment": [], "externalConsole": false, "MIMode": "gdb", "miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "C/C++: g++.exe 生成活动文件" } ]}
到现在为止,配置基本上完成了百分之80
剩下的调试还不完美,等我研究明白的~
赞 (0)
