vscode 远程 开发 centos7 c语言

本地vscode,搭建centos7的c语言开发环境

  • 远程主机一台或本地虚拟主机一台;本地电脑需要安装vscode的软件,vscode下载链接;vscode需要安装remote-ssh插件
    *vscode的debug参考文档

  • 远程主机

    • 安装gcc yum install -y gcc gdb
    • 查看gcc是否安装成功,gcc -v
  • vscode用远程开发工具链接到centos

    • 打开插件市场,搜索c/c++
    • 重启vscode
#创建一个文件夹
mkdir demo
touch main.c
# include <stdio.h>

int main(void) {
    printf("hello, world\n");
    return 0;
}
  • vscode选择顶部菜单栏依次选择 Terminal > Configure Default Build Task,并在弹出框里选择 C/C++: gcc build active file。
{
	"version": "2.0.0",
	"tasks": [
		{
			"type": "cppbuild",
			"label": "C/C++: gcc 生成活动文件",
			"command": "/usr/bin/gcc",
			"args": [
				"-fdiagnostics-color=always",
				"-g",
				"${file}",
				"-o",
				"${fileDirname}/build/${fileBasenameNoExtension}"
			],
			"options": {
				"cwd": "${workspaceFolder}"
			},
			"problemMatcher": [
				"$gcc"
			],
			"group": {
				"kind": "build",
				"isDefault": true
			},
			"detail": "编译器: /usr/bin/gcc"
		},
	]
}
  • vscode创建一个launch.json,选择Add Debug Configuration,选择g++ build and debug active file.
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "Set Disassembly Flavor to Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ],
            "miDebuggerPath": "/usr/bin/gdb",
            "preLaunchTask": "C/C++: g++ build active file"
        },

    ]
}
posted @ 2023-07-08 15:59  phper-liunian  阅读(109)  评论(0编辑  收藏  举报