工欲善其事 its prerequisite, an efficient code-checking tool can greatly improve our development efficiency. Flycheck is a common code compilation checker in Emacs, which documents some of the problems and workarounds that are encountered when configuring it.
The basic principle of flycheck is simple, that is, when you need to do a check (the timing may be you save a file, or change the file open after idle for some time), using the compilation tool to compile your current source file, a problem is displayed in the current buffer. For C + + code, it is done by using GCC or g++ to compile the current source file once. Understand the principle, after encountering a problem is good to solve.
1, error row highlighting problem
I want to change the way the error line is highlighted, my practice is to directly modify the Flycheck.el source file, for C + + code, modify the following places can be:
732(Defface flycheck-Error733 '(((( supports:underline (: Style wave) ) 734: Underline (: Style Wave:color"Cyan") 735: Background yellow)//I added this line. 736(t737: Underline t:inherit error)) 738 739 "Flycheck face for errors." 740:p ackage-version'(Flycheck. "0.13") 741: Group'flycheck-faces) 742
The purpose of my change is to change the background of the wrong row into yellow, which is more noticeable.
2, after opening the CPP file, Flycheck in the include display error, saying that the header file could not be found
Above said Flycheck work principle, find not the head file, indicating that flycheck when compiling source code with GCC did not find the header file, By reading the Flycheck.el code, you can specify the header file path by setting the variable Flycheck-gcc-include-path, and for a large C + + project, the header file may be scattered under many directories. This can be done by generating a file named. Dir-locals.el under the project root directory, which specifies the path to the header file for GCC compilation, as follows:
1 (C++-mode. ((Flycheck-gcc-include-path. ( 2 "/usr/include 3 " /home/cobbliu/thirdparty/gcc-4.9.2/include " 4 " /home/admin/jinxin/project/include 5 " /home/admin/jinxin/project/chunkserver/include )))))
If the header file directory is very numerous, you can generate Compile_commands.json through the bear, and then do some processing on Compile_commands.json to take out all the header file paths written to. Dir-locals.el
3, Flycheck does not work after you open the CPP file
I opened a CPP file, manually wrote a line of wrong code, but Flycheck does not work, this time need to see some flycheck in compiling the current file when the specific error, details see http://www.flycheck.org/en/ Latest/user/troubleshooting.html. Simply put, just use M-x flycheck-compile, and then type C/C++-GCC to let Flycheck manually compile it, the compilation information will be displayed in a separate buffer, Flycheck no work must be compiled at the time of the problem, Resolve each issue according to the problem shown in buffer.
4,.h file was not checked by Flycheck.
The. h file was opened by Emacs using C-mode and can be used in. Emacs to have Emacs open the. h file with C++-mode:
"("\\.h\\ "). C++-mode))
5,flycheck-compile found that there are too many compile errors, such as variables not defined and other errors
This is mainly because flycheck when using GCC to compile the source file, add the-wall option, to close the change, in. Emacs to modify the value of the variable flycheck-gcc-warnings, as follows:
' C++-mode-hook (Lambda () (setq flycheck-gcc-warnings nil))
But it is not recommended to do so.
Some problems encountered in Emacs Flycheck plug-in configuration