Skip to content
Looking up location of definition of symbol under cursor using Clang
C++ Emacs Lisp C Shell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


clang-lookup is a very simple CLI tool for navigation of C and C++ code bases
using the semantic analysis engine of the Clang compiler. Pass it a file, line
and column number on the command line and it will print warning/errors and a
line describing the location where the symbol at the given source location is

clang-lookup is designed to work out-of-the-box without any setup. The
disadvantage is that each invocation has to re-parse the given file. For large
projects some of the alternatives might work better (see end of this file).


To build you need to put a compiled version of LLVM 2.9 and Clang 2.9 into the
llvm directory. After configuring and building you should have the LLVM and
Clang binaries in llvm/Release/bin or llvm/Debug/bin.

Use "make" to create a release build of clang-extract and "make DEBUG=1" for a
debug build.


Call clang_lookup like this: "./build/ file line column". It will
output a list of compiler diagnostics (warnings, errors). If the symbol at the
given location could be resolved it will print a line describing the location of
it's definition as it's last output. The format is as follows


for example


If the symbol could not be resolved clang_lookup will print "location=" and
return a non-zero error code.


- add reasonable error handling
- add automated tests
  (using tests dir, pre-set locations and results)
- fix C++ support
  (use clang_createTranslationUnitFromSourceFile + clang_command_line_args)
- add customizable function to setup clang arguments (include paths, etc.)
- pass compiler errors and warnings on to flymake
- support reading source from stdin
- persistent/cached data base(?)

More info

Send feedback, bug reports, patches etc. to the following super-obfuscated
mail address: jrehders *at* gmx *dot* net

Other tools offering similar functionality.

Both create a persistant index on disk. This can be faster but requires a bit of

Mostly depend on regexps or similar hacks. They all are useful tools even for
large projects. Their indexing is less accurate than basing such information on
the compiler's analysis, though.

You can’t perform that action at this time.