按照博客大佬们的指导,给 VS Code 配置 C++ 语言环境,参考推荐:菜得扣↑的博客。根据指导,配置了 launch.json
,task.json
和 c_cpp_properties.json
三个文件。运行.cpp
文件时报错。
原图来自:https://www.pianshen.com/article/56791875146/。
根据问题描述,查找 “launch:program’…vscode\launch.exe’ dose not exist” 相关解决办法。浏览众多博客,解决方式主要围绕在确认launch.json
和tasks.json
的相关内容是否统一上,主要包括:
tasks.json
中的label
与launch.json
中的preLaunchTask
是否统一。此处的设置多种多样,只需要保证两者统一即可。参考博客3tasks.json
文件中的command
设置为g++
。参考博客4。按照此前的配置博客配置后,我此处为"C:\\TDM-GCC-64\\bin\\g++.exe"
,指向g++
编译器。task.json
中args
和launch.json
中program
的设置,将${workspaceFloder}
修改为${fileBasenameNoExtension}
。参考博客5。仔细查看了自己的配置文件,如下:
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,//弹出控制台窗口
"MIMode": "gdb",
"miDebuggerPath": "C:\\TDM-GCC-64\\bin\\gdb.exe",//自己调试器位置
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "C/C++: g++.exe build active file",
"command": "C:\\TDM-GCC-64\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "test",
"isDefault": true
}
}
]
}
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\TDM-GCC-64\\bin\\gcc.exe",
"cStandard": "c11",
"cppStandard": "gnu++14",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
确认三个文档的内容都没有问题。于是,又重新浏览了一边配置流程,发现一个问题:在配置c_cpp_properties.json
之前,.cpp
文件就编译为了.exe
。所以问题不在配置文档中的设置,而在于编译器的选择。搜索 “VS Code无法将.cpp编译为.exe”,找到示好的博客。问题出在shell上。
好吧,这一句 “Hello world !” 真难说出口。