I tried to add include path to flycheck
c/c++-clang, but it 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'm using emacs24
, flycheck.el
from package.el
and clang3.4
.
I do not want to get credit by this answer but it could be useful to someone.
Using the accepted answer and comments to set flycheck variable with Directory variables:
You have a project with the C++ source code in ~/myproject
.
Add the file ~/myproject/.dir-locals.el
with the following content:
((nil . ((eval . (setq flycheck-clang-include-path
(list (expand-file-name "~/myproject/include/")))))))
That worked for me.
Use expand-file-name
and ~
to refer to paths in your 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 run Clang, nor does it otherwise attempt to expand shell parameters in command lines. Hence, $HOME
is passed literally to Clang, which does obviously not work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With