【VSCode开发环境配置】

组织较多的源文件,配置CMake

安装C/C++、CMake、CMakeTool插件
Ctrl+Shift+P 搜索cmake kits配置kits,搜索cmake config
camke set build taregt设置编译目标
F7开始编译

组织较少的源文件,无需配置CMake

Using C++ on Linux in VS Code
需要配置三个文件:
tasks.json (compiler build settings)
launch.json (debugger settings)
c_cpp_properties.json (compiler path and IntelliSense settings)

${file} //当前文件全名
${fileDirname} //当前文件路径
${fileBasenameNoExtension} //当前文件无后缀名
${workspaceFolder} //当前工作区路径

注意:在编译或运行时要将当前查看文件切换到cpp文件上,因为"${file}"指的是当前文件

// task.json
{
	"version": "2.0.0",
	"tasks": [
		{
			"type": "cppbuild",
			"label": "C/C++: g++-8 生成活动文件",
			"command": "/usr/bin/g++-8",
			"args": [
				"-g",
				// "${file}",
				"${workspaceFolder}/*.cpp",
				"-o",
				"${fileDirname}/out/test.out"
			],
			"options": {
				"cwd": "${fileDirname}"
			},
			"problemMatcher": [
				"$gcc"
			],
			"group": {
				"kind": "build",
				"isDefault": true
			},
			"detail": "编译器: /usr/bin/g++-8"
		}
	]
}
{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "g++-8 - 生成和调试活动文件",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/out/test.out",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: g++-8 生成活动文件",
            "miDebuggerPath": "/usr/bin/gdb"
        }
    ]
}
{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/g++-8",
            "cStandard": "c11",
            "cppStandard": "c++14",
            "intelliSenseMode": "linux-gcc-x64"
        }
    ],
    "version": 4
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值