针对于vscode cpp mingw 环境的配置文件

其实感觉vscode用于cpp环境不是很方便,比如昨天配置环境就搞了半天时间。

针对于cpp的配置项。有三个文件需要配置,分别是工程属性、编译、调试的配置文件:

c_cpp_properties.json:

{
"configurations": [
{
"name": "Win32",
"browse": {
"path": [
"${workspaceFolder}",
"C: \\ cygwin64"
],
"limitSymbolsToIncludedHeaders": true
},
"includePath": [
"${workspaceFolder}",
"C: \\ cygwin64"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C: \\ cygwin64 \\ bin \\ g++.exe",
"cStandard": "c11",
"cppStandard": "c++11",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}

tasks.json:

{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build something",
"type": "shell",
"command": "g++",
"args":[
"${file}", "-o", "${fileBasenameNoExtension}.exe", "-g", "-std=c++11"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}

launch.json:

{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder} \\ main.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C: \\ cygwin64 \\ bin \\ gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "build something"
}
]
}

最后直接ctrl+shift+b 编译就行了。点击F5编译+调试。

==============================

另外一篇帖子上转过来的配置变量,比较实用:

${workspaceRoot} 当前打开的文件夹
${file} 当前打开的文件
${relativeFile} 相对于workspaceRoot的相对路径
${fileBasename} 当前打开文件的文件名
${fileDirname} 所在的文件夹,是绝对路径

${fileExtname} 当前打开文件的拓展名,如.json

===============================

官方文档规则+本地实际编译器调试器路径来配置,网上乱找一通各种问题,最后还是跟着官方文档比较好:

https://code.visualstudio.com/docs/languages/cpp

Tips:调试的时候无法命中断点,那肯定就是像我一样忘记在编译命令上面添加 “-g”了。

感谢这个issue:https://github.com/Microsoft/vscode-cpptools/issues/416,不然我还在想着升级cpp扩展工具。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值