VS Code 开发C/C++项目配置

2023-02-04  本文已影响0人  holly_wang_王小飞

【1】基础环境
远程操作系统:Debian GNU/Linux 9 \n \l
查看命令(linux):head -n 1 /etc/issue
创建工作目录:mkdir -p learn/day1/section1
远程操作系统安装clang:sudo apt install clang
本地环境:我的是mac
mac安装 VSCode:https://code.visualstudio.com/download;下载后双击安装
VS Code C/C++插件安装:
1.快捷键 Command + Shift + X

image.png
选择第一个进行安装

【2】配置VSCode 远程连接linux机器:https://www.jianshu.com/p/d92198e1313c?v=1675579178113
【3】开发一个项目试试环境
mac 本地打开步骤1种创建的远程工作目录
file > open 对话框输入远程目录

image.png

创建文件main.cpp
粘贴代码

#include <iostream>
using namespace std;

int main()
{
    cout << "hello world!" << endl;
    return 0;
}

进行配置Command + Shift + P

image.png

出现的对话框选择第一项


image.png

VS Code 会自动生成tasks.json

    "version": "2.0.0",
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: clang++ build active file",
            "command": "/usr/bin/clang++",
            "args": [
                "-fcolor-diagnostics",
                "-fansi-escape-codes",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build",
            "detail": "compiler: /usr/bin/clang++"
        }
    ]
} 

切换到main.cpp的界面执行Command + Shift + B

下方terminal种会出现编译成功输出

/usr/bin/clang++ -fcolor-diagnostics -fansi-escape-codes -g /home/wangxiaofei.holly/repos/toutiao/app/learn/day1/section1/main.cpp -o /home/wangxiaofei.holly/repos/toutiao/app/learn/day1/section1/main

Build finished successfully.
 *  Terminal will be reused by tasks, press any key to close it. 

执行:进入可执行文件目录

cd day1/section1/

执行

./main

输出
hello world!

上一篇 下一篇

猜你喜欢

热点阅读