Search code examples
pythonc++linuxllvm-clang

clang.cindex.LibclangError "Undefined symbol clang_CXXRecord_isAbstract"


I am trying to execute clang 5.0 with the next commands but it does not work.. I typed:

import clang

import clang.cindex

clang.cindex.Config.set_library_file('/usr/lib/x86_64-linux-gnu/libclang-5.0.so.1')

id = clang.cindex.Index.create()

and I received the following error:

clang.cindex.LibclangError: /usr/lib/x86_64-linux-gnu/libclang-5.0.so.1: undefined symbol: clang_CXXRecord_isAbstract. Please ensure that your python bindings are compatible with your libclang.so version.

I am using clang-5.0 with the bindings from https://github.com/llvm-mirror/clang


Solution

  • Windows

    I haven't tested this right now, but it worked a month ago for me.

    1. Either download the src code from github and go to /bindings/python/ and copy the clang directory and paste it into your python site packages dir or (try both) pip install clang-5

    2. Download the llvm binares. If you have python-32bit then install llvm 32bit!! Otherwise it wont work. For 64bit python install the 64bit binaries

    3. In your python program just import clang.cindex as cl and in your code do cl.Config.set_library_file("your/path/to/libclang.dll") libclang.dll should be in your clang/bin installation directory

    Linux

    Running it right now, so it works for me

    1. pip3 install clang-5

    2. from your package manager either get llvm-clang or llvm-clang-32bit depending on your python installation

    3. In your python program just import clang.cindex as cl and in your code do cl.Config.set_library_file("your/path/to/libclang.so")

    From my experience libclang.so should be located in either /usr/lib32/ or usr/lib64/

    Hope this helps!