下载g++/gcc
windows
windows下载MinGW-w64(已经包含g++)
pacman -S mingw-w64-ucrt-x86_64-gcc
|
之后把gcc的bin文件夹添加到系统PATH
之后验证
ubuntu
配置.vscode文件夹
tasks.json
tasks.json
文件是 VS Code 用于配置 C++ 编译任务的配置文件,它定义了如何用 g++ 编译你的代码
{ "version": "2.0.0", "tasks": [ { "type": "cppbuild", "label": "C/C++: g++.exe", "command": "g++", "args": [ "-g", "${file}", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe" ], "options": { "cwd": "${workspaceFolder}" }, "problemMatcher": ["$gcc"], "group": { "kind": "build", "isDefault": true } } ] }
|
launch.json
launch.json
文件是 VS Code 用于配置 C++ 调试器的文件,它定义了如何启动调试会话(如使用 GDB 调试 C++ 程序)
{ "version": "0.2.0", "configurations": [ { "name": "g++.exe - 生成和调试活动文件", "type": "cppdbg", "request": "launch", "program": "${fileDirname}\\${fileBasenameNoExtension}.exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": false, "MIMode": "gdb", "miDebuggerPath": "gdb", "setupCommands": [ { "description": "启用整齐打印", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "C/C++: g++.exe" } ] }
|
c_cpp_properties.json
c_cpp_properties.json
是 VS Code 的 C/C++ 扩展(Microsoft C/C++ 插件)的配置文件,用于控制 代码智能提示(IntelliSense)、头文件路径、编译器设置 等。它的作用和tasks.json
、launch.json
不同,是专门为编辑体验服务的
{ "configurations": [ { "name": "Linux", "includePath": [ "${workspaceFolder}/**" ], "defines": [], "compilerPath": "/usr/bin/gcc", "cStandard": "c17", "cppStandard": "gnu++17", "intelliSenseMode": "linux-gcc-x64" } ], "version": 4 }
|