skip to Main Content

I have updated XCode(v. 16.0) and made sure the xcode command line tools (xcode-select version 2409) are updated.

I have installed the C/C++ VS Code extension v.1.21.6

My compiler path is set to /usr/bin/clang++

with the command clang++ --version I see the output:

Apple clang version 16.0.0 (clang-1600.0.26.3)
Target: arm64-apple-darwin24.0.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

If I follow the hello world tutorial at https://code.visualstudio.com/docs/cpp/config-clang-mac, I see a red squiggle for the first include with the error:

#include errors detected. Please update your includePath.

I have searched extensively across my filesystem and fond many directories that have iostream, each specific to a version of macos.

I have tried adding an additional includePath which does contain iostream:

/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1

but when i try to build I still get the error:

fatal error: 'iostream' file not found

The documentation makes it sound like if I have the correct complier path then it should work:

The extension uses the compilerPath setting to infer the path to the C++ standard library header files.

When I start up a XCode C++ project and build and run the same hello-world code it works fine. I’m new to C++ and not sure how to proceed troubleshooting and correctly pointing the VS Code C/C++ extension to the standard library.

c_cpp_properties file for reference:

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

tasks.json file for reference:

{
  "tasks": [
    {
      "type": "cppbuild",
      "label": "C/C++: clang++ build active file",
      "command": "/usr/bin/clang++",
      "args": [
        "-std=c++17",
        "-pedantic-errors",
        "-Wall",
        "-Weffc++",
        "-Wextra",
        "-Wconversion",
        "-Wsign-conversion",
        "-ggdb",
        "-Werror",
        "-fcolor-diagnostics",
        "-fansi-escape-codes",
        "-g",
        "${file}",
        "-o",
        "${fileDirname}/${fileBasenameNoExtension}"
      ],
      "options": {
        "cwd": "${fileDirname}"
      },
      "problemMatcher": [
        "$gcc"
      ],
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "detail": "Task generated by Debugger."
    }
  ],
  "version": "2.0.0"
}

Running clang++ directly on the command line produces this output:

clang++ -std=c++17 -g /Users/todd/temp/vscode-c++/hello-world.cpp -o /Users/todd/temp/vscode-c++/hello-world
/Users/todd/temp/vscode-c++/hello-world.cpp:1:10: fatal error: 'iostream' file not found
    1 | #include <iostream>
      |          ^~~~~~~~~~
1 error generated.

Update:
I can now get the hello world code to compile via the command line now with the isystem argument.

clang++ -std=c++17 -isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1 hello-world.cpp -o h
ello-world

2

Answers


  1. Thanks to John Kerl and hsiaofei, they found out that the fix to this issue is to uninstall and reinstall the xcode command line tools.

    Uninstall

    sudo rm -rf /Library/Developer/CommandLineTools
    

    Reinstall

    xcode-select --install
    
    Login or Signup to reply.
  2. This worked. I was having issues in VS code cmake extension. Then tried compiling manually with clang and that gave me a similar error. So definitely was something between clang and Xcode.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search