0

I have 2 versions of clang in my system. One installed using brew and another one it was required by XCode (which is set by default and referred as "Apple clang"). Previous answers, here or guides [1], [2], [3] weren't useful for me.

BTW brew noted clang/llvm as a "keg-only" package. I've uninstalled xcode-tools, but for example later when I used otool a xcode window popped requiring to install xcode-tools... Anyway, I have this setup right now:

/usr/bin/clang <--- This one installed by XCode tools
/usr/local/Cellar/llvm/<version>/bin/clang <---- This one installed by homebrew

Now I am in a situation where I want to compile with the clang version installed by homebrew using VS code, but I didn't found any config files to switch from xcode clang to "homebrew" clang.

These are my config files so far:

tasks.json (manually changed command entry)

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: clang build active file",
            "command": "/usr/local/Cellar/llvm/13.0.1_1/bin/clang",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "compiler: /usr/local/Cellar/llvm/13.0.1_1/bin/clang"
        }
    ]
}

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**",
                "/usr/local/Cellar/llvm/13.0.1_1/include/**",
            ],
            "defines": [],
            "macFrameworkPath": [],
            "compilerPath": "/usr/local/bin/gcc-11",
            "cStandard": "gnu17",
            "cppStandard": "gnu++17",
            "intelliSenseMode": "macos-gcc-x64"
        }
    ],
    "version": 4
}

A sample version.c file

#include <clang-c/Index.h>
#include <stdio.h>

void show_clang_version(void) {
        CXString version = clang_getClangVersion();
        printf("%s\n", clang_getCString(version));
        clang_disposeString(version);
}

int main( int argc, const char *const * argv )
{
        show_clang_version();
        return 0;
}

This is the error I get

Starting build...
/usr/local/Cellar/llvm/13.0.1_1/bin/clang -fdiagnostics-color=always -g /Users/bel/libclang-test/vs-project/version.c -o /Users/bel/libclang-test/vs-project/version
/Users/bel/libclang-test/vs-project/version.c:1:10: fatal error: 'clang-c/Index.h' file not found
#include <clang-c/Index.h>
         ^~~~~~~~~~~~~~~~~
1 error generated.
user1000565
  • 927
  • 4
  • 12

0 Answers0