Table of Contents
- 1. Setup Cpp/C Development Environment in Spacemacs
- 1.1. 1. Add c/c++ layer
- 1.2. 2. Makefile and Source code in the same directory
- 1.3. 3. Makefile in different directory
- 1.4. 4. Clang Complete
- 1.5. 5. Debug
- 1.6. Todo
Based on Eivind Fonn's tutorial [https://www.youtube.com/watch?v=OjbkCEkboA8]
Simply add this
(c-c++ :variables c-c++-enable-clang-support t)
dotspacemacs-configuration-layers, like this:
... dotspacemacs-configuration-layers '( ... (c-c++ :variables c-c++-enable-clang-support t) ... ) ...
This configuration will enable
clang support, so you have to
clang has been installed.
This is the simplest situation, that you can open any source code file,
SPC c c for compilation.
SPC c C is for specifying compilation command, sometimes need this
for enabling debug mode.
In this situation we need to specify the location of
.dir-locals.el file is needed for this purpose.
should be placed in project root. The file content looks like this:
((c++-mode (helm-make-build-dir . "build/")))
build/is relative to project root directory.
Emacs will ask if the variable
Put the configuration in
.spacemacsto prevent this.
(put 'helm-make-build-dir 'safe-local-variable 'stringp)
If the project depends on third party libraries or header files in special locations,
clang will not figure out how to analyze source codes and provide auto-complete tips. We need
.clang_complete file to specify the compilation flags. That
file can be generated by
cc_args.py, which is a tool provided by
clang-complete project. Otherwise, The simplest way to install
think is move the file to
The video by Eivind Fonn demonstrates how to use
cmake. [28:00 - 29:40].
CXX="cc_args.py g++" cmake ...#other flags
I find the codes below can work with
make system directly, but
it will invoke the compilation process. And the compilation process
always been interrupted by errors, though it can generate the
.clang_complete file. This may cause incomplete compilation flags
CXX="cc_args.py g++" make all
Turn off Warnings about unused variables
So the target executable file will contain debug information.
The GUD interface in Spacemacs has a problem, which cause the current line indicator disappeared.