Questions tagged [libclang]

LibClang is a stable high level C interface to the clang compiler.

LibClang is a stable high level C interface to clang.

When in doubt, LibClang is probably the best clang interface to use, since it:

  • can be called from any language interfaced with C (python bindings come out of the box),
  • is stable,
  • provides high enough abstraction over clang's implementation details.

LibClang provides the following features:

  • C/C++/ObjC/ObjC++ code parsing and syntax checking,
  • AST indexing and cross-referencing,
  • source code tokenization (e.g. for syntax highlighting),
  • code completion.

Useful links

Related tags

230 questions
6
votes
0 answers

Libclang python bindings on windows

I'm trying to explore libclang (on Windows) to do "stuff*" based on parsing the AST. I find several examples, I'm unable to get anything to work. When I try to run this index = clang.cindex.Index.create() tu = index.parse(sys.argv[1], args=['-x',…
g3cko
  • 920
  • 1
  • 6
  • 21
6
votes
2 answers

Generate assembly from C code in memory using libclang

I need to implement a library that compiles C code to eBPF bytecode using LLVM/Clang as backend. The codes will be read from memory and I need to get the resultant assembly code in memory too. Until now, I have been able to compile to LLVM IR using…
Gerard Garcia
  • 125
  • 1
  • 10
6
votes
1 answer

Just-in-time compilation using libclang and LLVM C

I have a software that is able to generate C code that I would like to use in a just-in-time compilation context. From what I understand, LLVM/Clang is the way to go and, for maintainability of the project, I'd like to use the C API of llvm and…
Joel
  • 1,295
  • 15
  • 30
6
votes
1 answer

possible to share work when parsing multiple files with libclang?

If I have multiple files in a large project, all of which share a large number of included header files, is there any way to share the work of parsing the header files? I had hoped that creating one Index and then adding multiple translationUnits to…
ajp
  • 1,723
  • 14
  • 22
6
votes
2 answers

How can I skip includes using libclang?

I am using libclang to parse a objective c source code file. The following code finds all Objective-C instance method declarations, but it also finds declarations in the includes: enum CXCursorKind curKind = clang_getCursorKind(cursor); CXString…
mc_plectrum
  • 363
  • 4
  • 12
5
votes
0 answers

How do I resolve a failure to compile librocksdb-sys error on RHEL 7?

I have been trying to build the Canvas Data Loader. I've gone as far as step 10 and it's been pretty easy for me to resolve dependencies on a cargo build fail, but I've been stuck trying to resolve the librocksdb-sys v5.14.2 dependency for the past…
5
votes
1 answer

Using libclang 6.0.1: stddef.h not found

To get started with libclang, I build a very simple program that tries to load a very simple source file. It fails with 'stddef.h' file not found. Here is the program using libclang: #include int main() { CXIndex index =…
ygramoel
  • 669
  • 1
  • 6
  • 18
5
votes
0 answers

How to parse function attributes using libClang?

I'm trying to parse function attributes using libClang but so far am unnsuccessful. For example, I may have an attribute like this defined in a header. #define __mobile__ __attribute__((mobile)) And in a separate .cpp file I have my function…
ProgrammingRain
  • 173
  • 1
  • 1
  • 6
5
votes
4 answers

Doxygen: cannot find the shared library(s) 'libclang.so.6'

While running doxygen I get the following error: doxygen: error while loading shared libraries: libclang.so.6: cannot open shared object file: No such file or directory I have installed doxygen using sudo apt install doxygen on Ubuntu 17. In…
arpanmangal
  • 1,770
  • 1
  • 17
  • 34
5
votes
4 answers

How to get function definition/signature as a string in Clang?

How can I get a function's signature (or at least the entire definition?) as a string using Clang/Libclang, assuming I have its CXCursor or so? I think that the definition may be somehow obtainable by using the cursor's extents, but I don't really…
PhantomR
  • 605
  • 4
  • 16
5
votes
2 answers

Function boundary identification using libclang

I am learning to parse C++ files using Python + libclang with the help of this very informative (but slightly outdated) tutorial by Eli Bendersky. My objective is to parse C++ files and identify the function boundaries for functions present in those…
Maggie
  • 5,923
  • 8
  • 41
  • 56
5
votes
1 answer

Using libclang to parse in C++ in Python

After some research and a few questions, I ended up exploring libclang library in order to parse C++ source files in Python. Given a C++ source int fac(int n) { return (n>1) ? n∗fac(n−1) : 1; } for (int i = 0; i < linecount; i++) { sum +=…
user6167676
5
votes
2 answers

Break after control statements in clang-format

I'm using BreakBeforeBraces: Allman in my .clang-format file, but braces in control statements (such as if, for, while, ...) are not being put on their own line. // Currently: void foo() { while(true) { bar(); } } // What I…
Vittorio Romeo
  • 90,666
  • 33
  • 258
  • 416
5
votes
2 answers

Why can't this python script find the libclang dll?

I would like to get started with using libclang with Python. I am trying to get a sample code (http://www.altdevblogaday.com/2014/03/05/implementing-a-code-generator-with-libclang/) to work on Windows, here is a part of the code I'm trying to…
Mark Vincze
  • 7,737
  • 8
  • 42
  • 81
5
votes
2 answers

libclang: missing some statements in the AST?

I've wrote a test program (parse_ast.c) to parse a c source file (tt.c) to see how libclang works, the output is the hierarchical structure of the AST: Here is the test file: /* tt.c */ // line 1 #include…
jayven
  • 770
  • 8
  • 19
1 2
3
15 16