Emacs cannot compete with another other IDE if it doesn’t have an auto completion function. Auto-complete simply makes me a more efficient programmer. I know of the Auto Complete Mode extension, but it does not work with C++.


How can I achieve smart and efficient autocompletion for C++?

This question was originally asked by Malabarba on the Area 51 proposal: How to get intelligent auto-completion in C++?

  • 1
    It would be nice to expand a bit on this question. It has a lot of potential value, but right now the question is just the title.
    – Malabarba
    Commented Oct 7, 2014 at 22:10
  • Irony-mode seems to be the way to go at this time.
    – Sevki
    Commented Oct 7, 2014 at 22:58

6 Answers 6


Disclaimer: I'm the author of irony-mode

company-irony screenshot

If you just want smart auto-completion, I can recommend irony-mode with company-irony.

  • irony-mode is easy to install thanks to MELPA
  • the completion is very accurate and the performance quite decent thanks to libclang
  • with company-irony you have an asynchronous completion backend that will not get in your way if the completion takes some time
  • company-irony supports overloaded functions and if you have Yasnippet installed the function arguments are inserted as placeholders to fill-in
  • if your project uses Doxygen, the brief documentation of the completion candidate is displayed in the minibuffer (see screenshot)
  • the installation of irony-mode server on a Unix-like system (Linux, OS X) should be easy. Windows on the other hand requires a bit of tweaking but it is documented in the wiki

Another tool that hasn't been cited yet is emacs-ycmd.

  • 2
    Thank you so much! Wish I found out sooner about irony-mode Commented Oct 10, 2014 at 9:46
  • @GuillaumePapin Thanks for writing irony! Would you happen to have any timing benchmarks available? I have noticed that calls to clang_codeCompleteAt with a parsed TU(but unsaved changes) takes 3-5 seconds. Is irony-mode faster than this?
    – Pradhan
    Commented Nov 19, 2014 at 18:38
  • 1
    Irony uses libclang/clang_codeCompleteAt, so you won't get better times than that. 3-5 seconds may be too much depending on the context (e.g. completions at global scopes take much more time than other scopes). You can take a look at some timings that I did recently: github.com/Sarcasm/irony-mode/issues/131#issuecomment-60008803 Commented Nov 20, 2014 at 8:24
  • Related, for future readers: github.com/Sarcasm/irony-mode/issues/140 Commented Dec 8, 2014 at 20:50
  • How do the roles of irony-mode and emacs-ycmd compare? Are they alternatives to one another? Would it ever make sense to use both? Commented Mar 1, 2015 at 18:53

Check my guide. It lists several methods for auto-completion in C/C++.

Those options are:

  • Using Irony. Highly recommended, since it uses Clang and easy to setup compared with other solutions.

  • Using the built-in parser from Emacs. It is the best auto-complete you can get is from within Emacs parser, Semantic, but it would be slow on large project like Linux kernel.

  • Using company-mode package with company-clang. Provides code completion fine for system include paths since it can automatically get the paths from Clang, but has to do some configuration for project local

  • Using company-mode with company-gtags. It uses tag database generated from GNU Global as completion. You can use this to provide code complete locally to your project. It's not exactly intelligent since it throws everything inside the generated database to you.

  • rtags goes farther by providing a server for live analysis. But it's complicated to setup compare with pure Elisp solution.

  • I would not agree that setting up rtags is more complicated than a pure emacs lisp solution. Pure emacs lisp solution usually do not consider cmake/build files and are hardly able to find any header. Rtags is pretty easy to setup in comparison. It's just still a bit young as a project, with not very good test coverage.
    – baol
    Commented Jul 2, 2016 at 20:06
  • Nice addition to Tuhdo's guide: syamajala.github.io/c-ide.html
    – Victor
    Commented Jul 26, 2017 at 8:05

I've had great success with RTags + Company.

RTags needs a separate daemon rdm running that uses clang for code-completion, code-navigation and refactoring. rdm also functions as a database of symbols, meaning that autocompletion is much faster than any solution just directly calling clang_codeCompleteAt.

Rdm needs info of compilation flags for your projects which can be a hassle, but if you follow the advice from the RTags page and symlink gcc-rtags-wrapper.sh to gcc, g++, cc and c++ rdm automatically gets updated with new compilation flags on recompile.

  • I just switched over from irony-mode to rtags. Irony-mode constantly craps out and stops working after about 15 mins or so. Rtags seems pretty good so far, and has cleaner integration with yasnippet.
    – nenchev
    Commented Jan 28, 2016 at 17:59

Solution 1: company-mode + clang

The only issue is you need tell company-mode where to search your project's c/c++ header files.

If you use cmake, you can let https://github.com/redguardtoo/cpputils-cmake to do the setup for you (HINT: I'm the author of cpputils-cmake).


Solution 2: company-mode + gnu global

Nothing more to say, you need build the tags with gnu global cli tool, as others mentioned.


M-x semantic-mode



Tags Tables

find . -name "*.[chCH]" -print | etags -


etags, ctags - generate tag file for Emacs, vi


C-M-i (or M-TAB) completion-at-point. If Semantic mode enabled, tries to use Semantic parser data. If Semantic mode disabled or fails, tries to complete using selected tags table (see Tags)


M-. (find-tag) prompts tag name && jump to definition



I've been using cmake-ide to configure rtags, flycheck, irony, and company-clang.

Now you can configure your build system and your favorite static analysis emacs plugins at the same time!

EDIT: Note that company clang provides autocompletions, which was the feature you were looking for. cmake-ide can also configure flycheck and rtags, which adds several more IDE-like features.

  • 1
    Please explain how this answers the question of how to get C++ autocompletion.
    – Drew
    Commented Feb 15, 2017 at 22:40
  • @Drew company-clang provides completions Commented Feb 16, 2017 at 1:13
  • Please put it in your answer. Thx.
    – Drew
    Commented Feb 16, 2017 at 4:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.