Hello.
I am new to LLVM and need a bit of help to setup to start building.
Currently I have 2 versions of clang in my system.
- Installed using brew and
- Installed by XCode (which is set by default and referred as “Apple clang”).
I researched how to configure VisualStudio Code and get answers, here or guides [1], [2], [3] but weren’t useful for me.
(BTW brew noted clang/llvm as a “keg-only” package. I’ve uninstalled xcode-tools, but 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/Cellar/llvm/13.0.1_1/bin/clang",
"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.
I know that llvm-config can provide me with the right paths, but I don’t know where to put them in the configuration files. I am not using CMake since I just started with LLVM.
Any ideas?