当前位置:   article > 正文

Mac VScode C++开发环境配置_mac vscode intellisense配置

mac vscode intellisense配置

Mac VScode C++开发环境配置

一 需要安装的模块

  C/C++
  C/C++ Clang Command Adapter
  Code Runner
  CodeLLDB
  • 1
  • 2
  • 3
  • 4

二 配置文件

c_cpp_properties.json

Ctrl + Shift + P,找到后点击,则会在工作目录中多出一个 .vscode 目录,进入,会有一个c_cpp_properties.json文件,我们就将要在这里面配置需要的头文件。
然后打开命令行,输入gcc -v -E -x c++ -
将上述得到的信息最下面的那些路径,添加到刚才vscode创建的c_cpp_properties.json中,如下所示,这样#include后面就不会出现红色波浪线了。

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**",
                "/usr/local/include/**",
                "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/**",
                "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.5/include/**",
                "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/**",
                "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/**",
                "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/**"
            ],
            "defines": [],
            "macFrameworkPath": [],
            "compilerPath": "/usr/local/bin/gcc-10",
            "cStandard": "gnu17",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "macos-gcc-x64"
        }
    ],
    "version": 4
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

tasks.json

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++ build active file",
            "command": "/usr/bin/g++",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27

launch.json

{
    // 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": "g++ - Build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "lldb",
            "preLaunchTask": "C/C++: g++ build active file"
        }
    ]
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

setting.json

问题描述:VS Code中出现“未定义标识符”,可以右键“转到声明”,但会一直出现红色提醒。

问题原因:VS Code intellisense不能自动找到需要的头文件路径,需要在用户设置中强制intellisense使用Tag Parser,递归方式检索头文件。

解决方式:找到工程对应的settings.json,并复制以下两个语句,在其中配置使用Tag Parser方式。

{
    "C_Cpp.intelliSenseEngineFallback": "Disabled", //需要添加的
    "C_Cpp.intelliSenseEngine": "Tag Parser",  //  需要添加的

}
  • 1
  • 2
  • 3
  • 4
  • 5

参考文章:
https://blog.csdn.net/qq_43784626/article/details/111638186
https://www.icode9.com/content-1-790824.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/秋刀鱼在做梦/article/detail/957355
推荐阅读
相关标签
  

闽ICP备14008679号