vscode搭建c/c++问题解决
·
1、先参考下面的文章安装软件
2、按照上述安装后,运行程序时无输出,本来应该打印"hello word\n"

(1)、命令gcc where
先查询系统有几个gcc,找到对应的路径
(2)、gcc-v命令
查询gcc的版本,默认生效的是C:\Strawberry下面的gcc,我安装的mingw在D盘。
即使在环境变量中把mingw的路径放到最前面,默认生效的还是C:\Strawberry下面的gcc。
(3)、解决办法一、删除环境变量中的Strawberry路径名
然而并没有什么效果
(4)、解决办法二、检查launch.json、tasks.json里面配置的编译器路径
- tasks.json内容如下:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc.exe 生成活动文件",
//"command": "C:\\Strawberry\\c\\bin\\gcc.exe", //原来的路径
"command": "D:\\Program Files\\mingw64\\bin\\gcc.exe", //修改后的路径
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
],
"version": "2.0.0"
}
- launch.json内容如下:
{
"configurations": [
{
"name": "C/C++: gcc.exe 构建和调试活动文件",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
//"miDebuggerPath": "C:\\Strawberry\\c\\bin\\gcc.exe", //原来的路径
"miDebuggerPath": "D:\\Program Files\\mingw64\\bin\\gdb.exe", //修改后的路径
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "将反汇编风格设置为 Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: gcc.exe 生成活动文件"
}
],
"version": "2.0.0"
}
(5)、调用pthread函数时,编译通过,运行不通过
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc.exe 生成活动文件",
"command": "D:\\Program Files\\mingw64\\bin\\gcc.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-lpthread" //加上pthread的编译选项
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
],
"version": "2.0.0"
}
更多推荐


所有评论(0)