VsCode配置C/C++环境

https://zhuanlan.zhihu.com/p/87864677

https://www.jianshu.com/p/febbf1e975b6?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

https://blog.csdn.net/sinat_34524528/article/details/85890657

https://blog.csdn.net/qq_37868450/article/details/105013325

https://www.cnblogs.com/iwiniwin/p/13705456.html

https://code.visualstudio.com/docs/cpp/config-linux

https://www.jianshu.com/p/ad29eee7b736

https://www.cnblogs.com/iwiniwin/p/13705456.html

https://blog.csdn.net/ly2467513805/article/details/106864342/

 

1、Linux下使用vscode编译代码

1)安装软件

需要安装的软件有:VSCode、Cmake、GDB、GCC/G++。

安装VSCode C/C++插件,

tasks.json:用于编译等,免于我们命令行手动敲命令,设置完成后,使用快捷键Ctrl+Shift+p调出命令输入窗口,输入tasks 从提示框中找到Run Build Task,点击执行任务或者提示更多任务选项。

{
  // See https://go.microsoft.com/fwlink/?LinkId=733558
  // for the documentation about the tasks.json format
  "version": "2.0.0",
  "tasks": [
    {
      "label": "build", //取个名字,label用于launch.json的preLaunchTask
      "type": "shell",
      "command": "g++ -g hello.cpp -o hello", //执行的命令
      "group": {
        //从这里
        "kind": "build",
        "isDefault": true
      }, //到这里,设置为默认构建任务,按Ctrl+Shift+B立即执行,不必选择
      "problemMatcher": "$gcc"
    }
  ]
}
{
	"version": "2.0.0",
	"tasks": [{
			"label": "build & debug file",
			"type": "shell",
			"command": "g++",
			"args": [
				"-g",
				"-o",
				"${fileBasenameNoExtension}",
				"${file}"
			],
			"group": {
				"kind": "build",
				"isDefault": true
			}
		},
		{
			"label": "build & run file",
			"type": "shell",
			"command": "g++",
			"args": [
				"-o",
				"${fileBasenameNoExtension}",
				"${file}"
			],
			"group": {
				"kind": "build",
				"isDefault": true
			}
		}
	]
}

launch.json:用于调试,需要调试的用例名称,用例参数配置于此,在运行和调试界面(Debug)找到任务信息。

其中的miDubuggerPath后的路径要改成你的mingw编译器的安装路径

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [{
        "name": "(gdb) Launch",
        "type": "cppdbg",
        "request": "launch",
        "preLaunchTask": "build", // 调试前执行名为build的任务(先编译)
        "program": "${workspaceFolder}/hello.exe", //当前目录下要执行的程序名称
        "args": [--gtest_filter=ftClassName.test_name_1:ftClassName1.test_name_2], // 参数
        "stopAtEntry": false,
        "cwd": "${workspaceFolder}",
        "environment": [],
        "externalConsole": true,
        "MIMode": "gdb",
        "miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe", //gdb调试工具的路径
        "setupCommands": [{
            "description": "Enable pretty-printing for gdb",
            "text": "-enable-pretty-printing",
            "ignoreFailures": true
        }]
    }]
}
{
	"version": "0.2.0",
	"configurations": [{
			"name": "Run C/C++",
			"type": "cppdbg",
			"request": "launch",
			"program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",
			"args": [],
			"stopAtEntry": false,
			"cwd": "${workspaceFolder}",
			"environment": [],
			"externalConsole": true,
			"MIMode": "gdb",
			"miDebuggerPath": "C:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin/gdb.exe",
			"setupCommands": [{
				"description": "Enable pretty-printing for gdb",
				"text": "-enable-pretty-printing",
				"ignoreFailures": false
			}],
			"preLaunchTask": "build & run file"
		},
		{
			"name": "Debug C/C++",
			"type": "cppdbg",
			"request": "launch",
			"program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",
			"args": [],
			"stopAtEntry": false,
			"cwd": "${workspaceFolder}",
			"environment": [],
			"externalConsole": true,
			"MIMode": "gdb",
			"miDebuggerPath": "C:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin/gdb.exe",
			"setupCommands": [{
				"description": "Enable pretty-printing for gdb",
				"text": "-enable-pretty-printing",
				"ignoreFailures": false
			}],
			"preLaunchTask": "build & debug file"
		}
	]
}

c_cpp_properties.json:用于配置函数关系跳转。

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值