How to add include path to flycheck c / c ++ - clang?

I tried adding the include path to flycheck c / c ++ - clang, but that didn't work.

I put foo.h in ~/local/include and added the following lines to init.el :

 (add-hook 'c++-mode-hook (lambda () (setq flycheck-clang-standard-library "libc++"))) (add-hook 'c++-mode-hook (lambda () (setq flycheck-clang-language-standard "c++1y"))) (add-hook 'c++-mode-hook (lambda () (setq flycheck-clang-include-path (list "$HOME/local/include/")))) 

And in a file called test.cpp I wrote

 #include <foo.h> 

flycheck said that

'foo.h' file not found

What am I doing wrong? I am using emacs24 , flycheck.el from package.el and clang3.4 .

+6
source share
2 answers

Use expand-file-name and ~ to reference the path in the home directory:

 (add-hook 'c++-mode-hook (lambda () (setq flycheck-clang-include-path (list (expand-file-name "~/local/include/"))))) 

Flycheck does not use the system shell to launch Clang, and otherwise does not try to extend the shell options on the command lines. Therefore, $HOME is literally passed to Clang, which obviously does not work.

+6
source

I do not want to get a loan from this answer, but it may be useful to someone. Using the accepted answer and comments to set the flycheck variable with Directory Variables :

You have a project with C ++ source code in ~/myproject .
Add the file ~/myproject/.dir-locals.el with the following contents:

 ((nil . ((eval . (setq flycheck-clang-include-path (list (expand-file-name "~/myproject/include/"))))))) 

It worked for me.

+1
source

Source: https://habr.com/ru/post/970504/


All Articles