clion indexing problems in Makefile project


Hi, I've just encountered a problem about clion not indexing my headers and macron definitions.

The situation is that, although the building process of the whole project can finish without error, Clion can't index some of my headers.


The Makefile project is a little bit complex, where the outermost Makefile recursively calls Makefiles in subdirectories, each subdirectory typically corresponds to a unique app, and the Makefile in each subdirectories again "include" other Makefiles in other places, which made the project rather complex (at least for clion to index, I think). The structure is illustrated as follows:

Within the Makefile of subappDir3, it only has 3 lines:

Due to some histotic factors, all the include statements for user defined files like  #include"myheader.h" are all written without any prefix paths( not like #include"dir1/dir2/myHeader.h"). For compiling, we have -I flag, but clion doesn't seem to be able to recognize this. 

To make clion index these headers, all I can think of for now is to write an addtional CMakelist.txt file and inside which, add the include dirs for each target and call the target in the outermost Makefile to do finish the rest. If this will work theoretically, please let me know and I will try that!  thanks!!! In the worst case, I can replace all Makefiles by new CMakelist.txt, but I'm not familiar with CMake, so this would probably take all my weekends...

 Is there any way to give clion a hint about where to find my header files just like giving -I to gcc? Or is there any other other way to fix this?


Hi there, I've solved this by taking advantage of rizsotto/Bear: Bear is a tool that generates a compilation database for clang tooling. ( to generate compilation database. In this way, Clion knows where to find my headers.



Just in case, CLion should take into account the -I flag if it's specified in Makefile. If you would like to investigate the issue, please let me know.



Thanks for responding.

Although I managed to help Clion index my headers, another problem occurred.

When coding without the compilation database, Clion will tell me which file is not found, which class is not defined, and syntactic errors in the code. For example, if I use a variable without declaring, Clion will report this error by the red waves under such variable, saying something like "xxx is not declared.".

After introducing the compilation database, in my case, it's just a compile_commands.json, to cooperate with the Makefile of the project, all error reporting has gone missing. Now, if I just open any source or header file, and then input some random garbage into the file, even without the semicolon at the end of the line, no error will be reported, not to mention syntactic error. I noticed that when working without the compilation database, the "Context: <>" at the bottom bar will always point out the right file, but after introducing the compilation database, it always says "no-context", as the following picture shows.


This is a very late response, but just for the record:

If a compilation database was properly generated and successfully imported in CLion (without errors/warnings), the context shouldn't be empty (shouldn't show "no-context"):


Please sign in to leave a comment.