Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring Flycheck to work with C++11

I am having significant trouble configuring flycheck for C++11. Right now, flycheck is flagging things like std::to_string(). The checker I am using is just g++. What can I add in the .emacs file such that flycheck will assume C++11 by default?

like image 202
mrQWERTY Avatar asked Jun 20 '15 03:06

mrQWERTY


2 Answers

Flycheck provides the option flycheck-gcc-language-standard for this purpose. You should not set it globally, because that will break checking of C files, but you can set it from c++-mode-hook with the following code in your init file:

(add-hook 'c++-mode-hook (lambda () (setq flycheck-gcc-language-standard "c++11"))) 

However, I would recommend against this. Instead, use Directory Variables to configure the language standard per project.

Open the root directory of your project in Dired with C-x d, and then type M-x add-dir-local-variable RET c++-mode RET flycheck-gcc-language-standard RET "c++11". This will create a .dir-locals.el file in the root directory of your project. Emacs reads this file whenever you visit a file from this directory or any subdirectory, and sets variables according to the rules in this file. Specifically, Emacs will now set the language standard for Flycheck syntax checking to C++ 11 for all C++ files in your project.

like image 76
lunaryorn Avatar answered Sep 23 '22 15:09

lunaryorn


Very good answers already. I just want to add, that if you use clang instead, then the variable needed to be modified is flycheck-clang-language-standard.

like image 24
alexpanter Avatar answered Sep 20 '22 15:09

alexpanter