A C/C++ minor mode powered by libclang
irony-mode is an Emacs minor-mode that aims at improving the editing
experience for the C, C++ and Objective-C languages. It works by using a
combination of an Emacs package and a C++ program (
irony-server) that uses
Integration with eldoc-mode: irony-eldoc
These dependencies will be installed automatically when using the standard installation procedure described below.
|cl-lib||Built-in since Emacs 24.3|
|json||Built-in since Emacs 23.1|
|YASnippet||Optional. May be used to provide post-completion expansion of function arguments|
irony-server provides the libclang interface to
It uses a simple protocol based on S-expression. This server, written in C++ and
requires the following packages to be installed on your system:
The recommended way to install
irony-mode and its dependencies is to use a
(add-hook 'c++-mode-hook 'irony-mode) (add-hook 'c-mode-hook 'irony-mode) (add-hook 'objc-mode-hook 'irony-mode) ;; replace the `completion-at-point' and `complete-symbol' bindings in ;; irony-mode's buffers by irony-mode's function (defun my-irony-mode-hook () (define-key irony-mode-map [remap completion-at-point] 'irony-completion-at-point-async) (define-key irony-mode-map [remap complete-symbol] 'irony-completion-at-point-async)) (add-hook 'irony-mode-hook 'my-irony-mode-hook) (add-hook 'irony-mode-hook 'irony-cdb-autosetup-compile-options)
irony-mode should work fine on Windows but there are some things to take care
libclang.dllis expected to be available in the
PATHor in Emacs’
Emacs >= 24.4 is required. A bug in previous versions makes irony unuseable (Emacs bug #18420).
w32-pipe-read-delaydefault value of
50should be changed. This should not cause any issue on today’s version of Windows. The default value of
50may be lowered in mainline Emacs in future versions, until then please add the following to your
(setq w32-pipe-read-delay 0)
On the first run,
irony-mode will ask you to build and install
To do so, type
M-x irony-install-server RET.
M-x customize-group RET irony RET
In order to provide context sensitive and accurate information,
needs to know about the compiler flags used to parse the current buffer. The
best way to achieve this is to use a
In order to work correctly,
irony-mode needs to know the compile flags.
irony-cdb aims to provide as automatic as possible compile flags discovery,
with minimal user input.
Please refer to
irony-cdb supports the following compilation databases:
JSON Compilation Database - A JSON formatted file generated by various build tools. The file is named
compile_commands.json, it lists the compile options associated to each file in the project.
CMake >= 2.8.5 will generate a compilation database in the build directory when issuing the following command
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON <...>.
ninja >= 1.2 will generate a JSON Compilation Database when using the
Bear generates a JSON Compilation Database file by “monitoring” the build of a project. The typical usage for a
make-based project will be
bear -- make -B.
.clang_complete - A file at the root of your project containing the compilation flags, one per line. This is compatible with the with plugin Rip-Rip/clang_complete. If you want to generate the
.clang_completeautomatically, take a look at the cc_args.py documentation.
More detailed information on compilation database is available here:
It’s slow, why?
A bug in old version of Clang (at least ‘3.1-8’) caused the completion to fail on the standard library types. To eliminate this bug an optimisation has been disabled in the parsing of a translation unit. This result in a slower parsing.
This only affect old versions of Clang (< 3.2), it is suggested to update your libclang installation if you want to take advantage of the optimizations.
libclang.so: cannot open shared object file…
irony-server succeed but you have the following message when you try
to run the
'irony-server: error while loading shared libraries: libclang.so: cannot open shared object file: No such file or directory
libclang is installed in a non-standard location (one that is missing
from the path list of the dynamic loader, see ld.so.conf) you can tell CMake
to use the rpath when installing the target
enable rpath in CMake use the following command:
cmake -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON <args...>
If you’re running OS X, you can also use
install_name_tool to explicitly
irony-server where an appropriate version of
For example, Homebrew (with
brew install llvm --with-clang) will install
libclang.dylib library at
you can instruct
irony-server to use this with something like:
install_name_tool -change @rpath/libclang.dylib /usr/local/opt/llvm/lib/libclang.dylib irony-server