Skip to content

Instantly share code, notes, and snippets.

@tasheng
Created March 25, 2018 11:03
Show Gist options
  • Select an option

  • Save tasheng/4e9e9ebc8e63ba30ff81dfdff0dbafbf to your computer and use it in GitHub Desktop.

Select an option

Save tasheng/4e9e9ebc8e63ba30ff81dfdff0dbafbf to your computer and use it in GitHub Desktop.

Setting up modern C++ development environment in Emacs

Current situation

Currently, rtags offers the best support for code navigation of a C++ project in Emacs. It uses clang as the back-end to parse the source code. Other tools such as ctags, gtags, csope, dumb jump, etc. relies on regexp matching using a tag file, that is fine for C projects but difficult to parse C++. Semantics parse the source code in elisp and thus might be too slow for large projects, and also fall behind the new C++ features. cquery is an emerging tool that seems promising, too.

It is said that irony offers better code completion than rtags.

Configuration

Both rtags and irony-mode require a compilation database for clang. Some tools such as cmake or ninja can produce this, but not for other tools. We will use bear to intercept the output of scons and make a database, as suggested by the author here.

Since bear works by intercepting the exec emitted by the child process, there is no need to add the --verbose flag, and it needs a full build from clean. example for using a locally installed bear with scons:

~/bin/bear/bin/bear -l ~/bin/bear/libear/libear.so scons trg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment