zoukankan      html  css  js  c++  java
  • Mac OS中使用VScode配置C语言开发环境

    个人博客 chinazt.cc

    闲话少叙,直奔主题

    • 下载VSCode
    https://code.visualstudio.com/download
    
    • 安装C/C++插件
      需要两个插件:
    1. cpptools
    


    这个插件用来查找头文件和源代码,用于代码提示。

    
    2.clang++
    
    


    这个插件用来自动编译源代码,如果你习惯使用makefile获取其它构建工具,那么可以不安装这个插件。

    • 配置插件

    1.进入命令行模式, 选择[C/Cpp: Edit Configurations]。生成c_cpp_properties.json,在对应的MAC节点中,根据实际需要修改头文件所在路径。

    2.进入命令行模式, 选择[Tasks: Configure Task Runner]。生成tasks.json,里面内容如下:

    {
        // See https://go.microsoft.com/fwlink/?LinkId=733558
        // for the documentation about the tasks.json format
        "version": "0.1.0",
        "command": "clang", //使用clang编译C文件,如果你使用C++开发,改成clang++
        "isShellCommand": true,
        "args": ["main.c", "-g"],//如果使用的是C++,则改成main.cpp或者相对应的cpp入口文件。如果需要支持C++11,添加"-std=c++11"
        "showOutput": "always"
    }
    

    3.进入命令行模式, 选择[Debug: Open launch.json]。生成launch.json文件,内容如下:

    {
        "version": "0.2.0",
        "configurations": [
    
            {
                "name": "C++ Launch (GDB)",
                "type": "cppdbg",
                "request": "launch",
                "targetArchitecture": "x86_64",
                "program": "${workspaceRoot}/a.out",
                "args": [],
                "stopAtEntry": false,
                "cwd": "${workspaceRoot}",
                "environment": [],
                "externalConsole": true,
                "MIMode": "lldb",
                "preLaunchTask": "clang"
            }
        ]
    }
    
    • 测试插件
    #include<stdio.h>
    
    int
    main()
    {
        printf("Hello World");
    }
    
    

    使用Shift+Command+B预期会自动编译出a.out。 执行F5预期可以自动进行debug。

  • 相关阅读:
    解决ORA-00257: 归档程序错误。在释放之前仅限于内部连接
    linux 监控脚本运行时间
    sqlserver中查询表字段的sql语句
    gpg无法生成密钥对的问题
    jdbc连接oracle的几种格式
    windows中使用tracert命令追踪路由信息
    MySQL编码问题探究
    Apache Storm Installation
    linux的swap相关
    awk
  • 原文地址:https://www.cnblogs.com/vikings-blog/p/6999520.html
Copyright © 2011-2022 走看看