Macbook Pro 安装vscode并配置c/c++环境

配置环境:Macbook Pro操作系统MacOS Catalina 10.15.4.

首先在浏览器中搜索vscode,打开搜索结果第一条,然后点击“Download for Mac”然后在页面停留一会就下载了vscode安装程序

Macbook Pro 安装vscode并配置c/c++环境_第1张图片

解压缩,

Macbook Pro 安装vscode并配置c/c++环境_第2张图片

将文件拉入应用程序即可。

Macbook Pro 安装vscode并配置c/c++环境_第3张图片

安装插件C\C++,C\C++ Clang Command Adapter,CodeLLDB(用来debug,解决Catalina不支持lldb调试问题)以及code runner(用来编译)。

Macbook Pro 安装vscode并配置c/c++环境_第4张图片

Macbook Pro 安装vscode并配置c/c++环境_第5张图片

Macbook Pro 安装vscode并配置c/c++环境_第6张图片

添加配置文件:tasks.json、launch.json、以及c_cpp_properties.json.

shift+command+P点击C/C++ 编辑配置(JSON),出现文件c_cpp_properties.json,

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "macFrameworkPath": [
                "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
            ],
            "compilerPath": "/usr/bin/clang",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

shift+command+B一直点击直到other,如下配置tasks.json文件。

{
    "version": "2.0.0",
    "tasks": [
      {
        "label": "Build with Clang",
        "type": "shell",
        "command": "clang++",
        "args": [
          "${file}",
                "-std=c++11",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}.out",
                "-g",
                "--debug"
        ],
        "group": {
          "kind": "build",
          "isDefault": true
        }
      }
    ]
  }

创建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": [
        {
            "type": "lldb",
            "request": "launch",
            "name": "Debug",
            "program": "${fileDirname}/${fileBasenameNoExtension}.out",
            "args": [],
            "cwd": "${workspaceFolder}"
        }
    ]
}

创建测试代码文件test.cpp

#include 
int main()
{
    for(int i=0;i<5;i++){
    std::cout<<"hey you"<

点击runcode 小三角运行结果:

Macbook Pro 安装vscode并配置c/c++环境_第7张图片

 

但是假如在for循环输出语句设置断点,调试控制台出现错误:

Warning: Debuggee TargetArchitecture not detected, assuming x86_64.

解决办法:

将之前的launch.json文件删除,添加lldb 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": [
     
       {
            "type": "lldb",
            "request": "launch",
            "name": "Debug",
            "program": "${fileDirname}/${fileBasenameNoExtension}.out",
            "args": [],
            "cwd": "${workspaceFolder}"
        }
    ]
}

设置断点:点击运行,按F5错误消失,并且按照每一步输出结果:

Macbook Pro 安装vscode并配置c/c++环境_第8张图片

另外需要注意的一点:如果更改了程序的内容,保存之后,需要重新shift+command+B,产生新的.out文件,这样再按F5调试才是修改后的结果,否则仍然是修改前的结果。

 

参考链接:

https://www.bilibili.com/video/BV1U741157Rd/?p=2&t=40

https://www.bilibili.com/video/BV1z7411N7Pg?from=search&seid=13295932737773533081

希望对大家有帮助。

你可能感兴趣的:(C++,编程语言,CSDN,c++,debug)