0

I am using Flycheck for my syntax highlighting which have been working out great when working with all header and source files in one directory.

I recently decided to add some unit tests to test my code which I added another directory for. The projects compiles and runs without problems. My problem is that in the test/Formula-test.cpp file when i #include "Formula.h" a header from the src/Formula.h folder flycheck can't seem to find it. I get the "error" 'Formula.h' file not found (c/c++-clang).

My project structure looks like this:

.
├── build
│   └── compile_commands.json
├── CMakeLists.txt
├── lib
│   └── googletest
├── src
│   ├── CMakeLists.txt
│   ├── Formula.cpp
│   ├── Formula.h
│   ├── main.cpp
└── test
    ├── CMakeLists.txt
    ├── Formula-test.cpp
    └── main.cpp

Is there any configuration or package that can fix this?

Here is my full config file: https://github.com/Zeppan/configs/blob/master/.emacs

  • 1
    Try to write #include "../src/Formula.h or add the src path in a .dir-locals.el file – Ian Nov 14 '19 at 14:45
  • It did work with #include "../src/Formula.h but it doesn't look very nice (good quick-fix however). Is there some way to make flycheck dependent on the CMakeLists.txt? I read that you could create a .clang_complete file but I didn't find any information of how to do that. – ZeppRock Nov 14 '19 at 15:05
1

Normally you may configure flycheck with what you need - see flycheck group of variables. But that may not be the best idea, since your path changes in another project. The package cmake-ide could instead manage all flycheck paths for your project and adds also compilation command.

About a .clang-complete file, here it is my version:

-DDEBUG
-I/Library/Developer/CommandLineTools/usr/include/c++/v1/
-I/Library/Developer/CommandLineTools/usr/include/
-I/usr/local/opt/boost/include/
-I/Users/your-name/Path-to-proj/

I use the above and a .dir-locals.el file. The reason for me was that I use eglot + clangd, and this package (eglot) disable flycheck in favour of flymake (seems actually there is a wave of replacing flycheck with flymake...)

  • Thanks! The cmake-ide package worked out great! It does however complains about stuff in the google-test library but at least it finds all the header files! – ZeppRock Nov 15 '19 at 9:16
  • I found that the google-test problem was not flycheck itself, it was one of my checkers, cppcheck to be exact. I removed it from my system and are using clang instead. – ZeppRock Nov 15 '19 at 9:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.