VSCode C++开发环境设置-更多C/C++配置 macOS版

VSCode C++开发环境设置-更多C/C++配置, 重点在于通过c_cpp_properties.json文件提供更多控制。

步骤
  1. 可以创建c_cpp_properties.json文件提供更多的C/C++扩展控制。例如改变编译器路径、包含路径、C++标准等。

  2. ⇧⌘P,在出现的下拉框中选择C/C++: Edit Configurations (UI)C/C++: Edit Configurations (JSON) ,一个是界面操作,一个是json文件操作

  3. 当前目录结构如下:

    helloworld
     |- .vscode
        |- tasks.json
        |- launch.json
        |- c_cpp_properties.json // C/C++配置文件- helloworld.cpp
    
  4. c_cpp_properties.json文件内容如下:

    {
        "configurations": [
            {
                "name": "Mac",
                "includePath": [
                    "${workspaceFolder}/**"
                ],
                "defines": [],
                "macFrameworkPath": [
                    "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
                ],
                "compilerPath": "/usr/bin/clang",
                "cStandard": "c11",
                "cppStandard": "c++98",
                "intelliSenseMode": "macos-clang-x64"
            }
        ],
        "version": 4
    }
    
  5. c_cpp_properties.json解释

    • includePath 包含路径
    • Compiler path 编译器路径,用它来推断C++标准库头文件路径,其寻找规则为:
      • PATH路径中已知编译器名称,
      • 硬编码的Xcode路径:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/
    • macFrameworkPath 系统头文件路径
  6. 复用

    • 将c_cpp_properties.json拷贝到新的工程目录的.vscode目录中即可
参考

官网

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值