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?
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:
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.
1
alexpanter
On
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.
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 fromc++-mode-hook
with the following code in your init file: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 typeM-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.