Irony
Irony is a C/C++ minor mode based on libclang, which aims context-sensitive completion and syntax checking using the clang compiler. To do so the following packages from (M)ELPA are needed:
- irony,
- company-irony (context-sensitive completion)
- company-irony-c-headers (header file name completion)
- flycheck (generic syntax checker)
- flycheck-irony (C/C++ syntax checking with clang)
But secondly (to get all that stuff working) the clang compiler must know the exact command line options. For that purpose a so called Compiler Database (CDB) must exist in a (sub-) directory, from irony-cdb-search-directory-list
. For details on that issue see:
- variable
irony-cdb-compilation-databases
Sometimes i simply use a static .clang_complete
file in project root directory, according to this one:
-std=c99 -Wall -Wextra -DDEBUG -D_DEBUG_ -D_GNU_SOURCE -D_REENRANT -I. -I./include -I/usr/include -I/usr/include/clang/3.8/include -I/usr/include/gsl -I/usr/include/glib-2.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/gtk-3.0
*.h
(or C++ header files w/o an extension) then option -D__cplusplus=201103L
(example for C++11) might be needed.
In case a project is using CMake then a file compile_commands.json
can be generated on each build.
For that purpose one has simply to add the following line to CMakeLists.txt
:
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
More information on Irony setup can be found on:
- Zuogong Yue: Emacs as C++ IDE,
- Nils Deppe: Using Emacs as a C++ IDE,
- Gregory J. Stein: C/C++ Completion In Emacs,
- Soonho Kong: How to Setup emacs irony-mode in Ubuntu-12.04,
- Martin Törnqvist: How to Setup emacs `irony-mode` in Ubuntu-12.04,
- Stack Exchange: Add include paths to flycheck and to company-irony?