Search code examples
c++linkerclangllvm-clanglibclang

Cannot link to libclang in OSX High Sierra


I have installed llvm and clang through brew.

When I compile a program with the header file "clang-c/Index.h", I get

Undefined symbols for architecture x86_64:
"_clang_createIndex", referenced from:
  _main in t-c9baef.o
....

Here is the command I used for compiling my program:

CXX=/usr/local/opt/llvm/bin/clang++ CPPFLAGS=-I/usr/local/opt/llvm/include make prog

I am using OSX High Sierra.


Solution

  • I have managed to fix the issue.

    The command I used for building is:

    CXX=/usr/local/opt/llvm/bin/clang++ \
    LDFLAGS+='-L/usr/local/opt/llvm/lib \
    -L/usr/local/Cellar/llvm/5.0.1/lib -lclang' \
    CPPFLAGS=-I/usr/local/opt/llvm/include \
    make myprog
    

    I had to link against the libclang.dylib and add -lclang