欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 运维知识 > linux >内容正文

linux

linux用vsc写c语言,vscode写c语言(windows)

发布时间:2023/12/10 linux 54 豆豆
生活随笔 收集整理的这篇文章主要介绍了 linux用vsc写c语言,vscode写c语言(windows) 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

用vscode学习c语言。

记录vscode配置c语言编译环境。

1.安装vscode(版本1.27)

2.安装c/c++扩展。

配置环境变量,以WIN10为例 ,此电脑-属性-高级系统设置-环境变量-系统变量-path-添加一条D:\Program Files\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin(你安装编译工具路径)

配置前

配置后

-ps:如果开着vscode配置环境变量,配置完要关掉vscode重开一次。

4.配置文件launch.json,task.json。

新建文件hello.cpp,

按F5弹出选择环境,配置launch.json

点击进去,configurations:里内容如下;

{

"name": "(gdb) Launch",

"type": "cppdbg",

"request": "launch",

"program": "enter program name, for example ${workspaceFolder}/a.exe",

"args": [],

"stopAtEntry": false,

"cwd": "${workspaceFolder}",

"environment": [],

"externalConsole": true,

"MIMode": "gdb",

"miDebuggerPath": "/path/to/gdb",

"setupCommands": [

{

"description": "Enable pretty-printing for gdb",

"text": "-enable-pretty-printing",

"ignoreFailures": true

}

]

}

修改成如下;

{

"name": "(gdb) Launch",

"type": "cppdbg",

"request": "launch",

"program": "${workspaceFolder}/a.exe",//这里删除前面那里的enter program name, for example

"args": [],

"stopAtEntry": false,

"cwd": "${workspaceFolder}",

"environment": [],

"externalConsole": true,

"MIMode": "gdb",

"miDebuggerPath": "D:\\Program Files\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\gdb.exe",//修改为你安装mingw32的路径

"setupCommands": [

{

"description": "Enable pretty-printing for gdb",

"text": "-enable-pretty-printing",

"ignoreFailures": true

}

],

"preLaunchTask": "build hello",//task.json里面的名字

}

回到hello.cpp按F5弹出报错框,选配置任务。

点击,然后选Others,出现task.json,如下;

"version": "2.0.0",

"tasks": [

{

"label": "echo",

"type": "shell",

"command": "echo Hello"

}

]

修改如下;

"version": "2.0.0",

"tasks": [

{

"label": "build hello",

"type": "shell",

"command": "g++",

"args": [

"-g", "hello.cpp",

],

"group":{

"kind": "build",

"isDefault": true

}

}

]

注意:如果是win32程序(窗口界面),args内加上"-mwindows"。

回到hello.cpp文件,按F5。成功运行编译。

5.还有就是发现中文控制台显示乱码,

只要点击右下角utf-8,

点使用编码保存,选GBK,然后F5运行

----------------------------------------------------------------------------------------------------------------------------------------

创作挑战赛新人创作奖励来咯,坚持创作打卡瓜分现金大奖

总结

以上是生活随笔为你收集整理的linux用vsc写c语言,vscode写c语言(windows)的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。