Enable C++ Development in VS Code on macOS (Clang + LLDB)

This guide walks you through a clean, step-by-step setup to compile and debug C++ in Visual Studio Code on macOS using Clang and LLDB.

This guide works on:

Note: Visual Studio Code does not include a compiler. Clang is provided via the Xcode Command Line Tools.


Prerequisites


Step 1: Install the C/C++ extension

  1. Open VS Code.
  2. Go to Extensions: Press Shift+Cmd+X.
  3. Search and install: Find C/C++ by Microsoft and click Install.
  4. Restart VS Code: Optional but helps the extension initialize cleanly.

Step 2: Install the C++ compiler and tools (Clang/LLVM via Xcode CLT)

  1. Open Terminal (Applications → Utilities → Terminal).
  2. Install Xcode Command Line Tools:
xcode-select --install
  1. Accept prompts and wait for installation to finish.
  2. Verify Clang is available:
clang++ --version

You should see a version output including Apple clang version.


Step 3: Create a test C++ project

  1. Create a project folder:
mkdir ~/cpp-hello && cd ~/cpp-hello

⚠️ If the code command is not found

Some macOS systems don’t have the VS Code command-line launcher enabled by default.

Enable it in two quick steps:

  1. Open VS Code.
  2. Press Cmd+Shift+P → type shell command → select Shell Command: Install ‘code’ command in PATH.

After that, the command below will work.

  1. Open the folder in VS Code:
code .
  1. Create a source file: In VS Code, add a new file named main.cpp.
  2. Add sample code:
#include <iostream>

int main() {
    std::cout << "Hello, C++ from macOS!" << std::endl;
    return 0;
}

Step 4: Configure build tasks (tasks.json)

  1. Create a .vscode folder: In your project, create .vscode/.
  2. Add tasks.json: Create .vscode/tasks.json with:
{
  "version": "2.0.0",
  "tasks": [
    {
      "type": "shell",
      "label": "C++: Build with clang++",
      "command": "clang++",
      "args": [
        "-std=c++17",
        "-g",
        "main.cpp",
        "-o",
        "build/main"
      ],
      "options": {
        "cwd": "${workspaceFolder}"
      },
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "problemMatcher": [
        "$gcc"
      ]
    }
  ]
}
  1. Create build directory: Optional but clean.
mkdir -p build

Notes:


Step 5: Configure debugging (launch.json)

  1. Add launch.json: Create .vscode/launch.json with:
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "C++: Debug build/main (LLDB)",
      "type": "lldb",
      "request": "launch",
      "program": "${workspaceFolder}/build/main",
      "args": [],
      "cwd": "${workspaceFolder}",
      "preLaunchTask": "C++: Build with clang++",
      "stopOnEntry": false,
      "environment": [],
      "console": "integratedTerminal"
    }
  ]
}

Step 6: Configure IntelliSense (optional but recommended)

  1. Add c_cpp_properties.json: Create .vscode/c_cpp_properties.json:
{
  "version": 4,
  "configurations": [
    {
      "name": "macOS",
      "compilerPath": "/usr/bin/clang++",
      "cStandard": "c11",
      "cppStandard": "c++17",
      "intelliSenseMode": "macos-clang-arm64"
    }
  ]
}
  1. Apple Silicon vs. Intel:

Step 7: Build and run

  1. Build: Press Cmd+Shift+B (or Terminal → Run Build Task). You should see build/main created.
  2. Run in terminal:
./build/main

Output should be:

Hello, C++ from macOS!
  1. Debug in VS Code:

Step 8: Add multiple files (optional)

If you add more .cpp files, either list them in args or use a wildcard with a simple build script:

Update tasks.json args:

"args": ["-std=c++17", "-g", "*.cpp", "-o", "build/main"]

For larger projects, consider a Makefile or CMake.


Step 9: Common issues and fixes


Step 10: Optional enhancements


Quick reference