CLion fails to find some of my headers. Where does it search for them?

CLion searches through the same places CMake does. Set the include_directories variable in CMake to provide the headers path to the IDE. More details on CMake configuration can be found in our Quick CMake Tutorial.

Since CLion 1.5 EAP there is also a new feature ‘Mark Directory As’ that allows to mark directories as:

  • Excluded
  • Libraries
  • Project sources and headers

Read more about use cases and details in our blog.

 

 

11 comments
Comment actions Permalink

I hope this helps.

cmake_minimum_required(VERSION 3.6)
project(untitled)

set(CMAKE_CXX_STANDARD 11)

#Set your directories. The dot representes the root application folder.
#Thus my the path to my domain folder:
set(APP_DOMAIN ./domain)
set(APP_CALC ./calc)

#Include the directories and now your cpp files will recognize your headers
include_directories(${APP_DOMAIN})
include_directories(${APP_CALC})

set(
SOURCE_FILES
main.cpp
${APP_DOMAIN}/person.h
${APP_DOMAIN}/person.cpp
${APP_CALC}/add.h
${APP_CALC}/add.cpp
)
add_executable(untitled ${SOURCE_FILES})

#CHEARS!
1
Comment actions Permalink

In my CMakeLists.txt I tried 

include_directories( ./src )

But still the line

#include <module.h>

is grayed out and GoTo Definition / Declaration doesn't work. When I change that to 

#include "module.h"

it does work as the .cpp file is in the same folder as the header. But I'm not allowed to use "". How do I make CLion find my headers included with #include <> ? Any help would be greatly appreciated.

0
Comment actions Permalink

I have the same issue: my header files are included as #include <xxx.h> and they are not recognised and all my struct definitions are red

I have included 

include_directories( ./src/include )
which is where my header files are
0
Comment actions Permalink

We can't reproduce the problem on our side. Could you please file a bug report and attach an isolated sample project?

Thanks in advance.

0
Comment actions Permalink

I have a project which builds inside an "SDK" in chroot environment. Project CMake build system is designed to be used from inside the SDK. I managed to build the project by specifying CMake from inside the SDK in CLion->Settings->Build,->Toolchains.

Problem is that build is working now, but proper indexing is not. CMake cache contains paths to includes relative to the SDK root. It makes make happy, but CLion can't resolve them.

Question is if there is any CLion configuration file where I can specify include paths for indexing?

0
Comment actions Permalink

V Krikun, could you please describe your configuration (and if possible, attach the generated cmake files) in CPP-2519?

 

0
Comment actions Permalink

In the case of opening an existing codebase, it would have been nice to mention here to use File > Import Project and follow the dialogs to have CLion automatically build the CMakeLists.txt.  Then magically I have a 6 page CMakeLists.txt that I never would have figured out on my own.  

0
Comment actions Permalink

I had a similar issue. My header files included with #include <...> were not recognized. I tried

include_directories(./lib)

but with no luck. After some hours of research, I found a post with a hint to try the SYSTEM flag in include_directories. This solved my problem:

include_directories(SYSTEM ./lib)

Until then, all headers were recognized.

2
Comment actions Permalink

I'd just like to add something; I was having this issue on a project copied from a different machine (same OS, Ubuntu 18.04) even though my include directories were correct. To fix it, I added the SYSTEM tag as above. However, removing the SYSTEM tag afterwards has no effect; everything still works. So clearly, CLion or CMake is caching something somewhere, and adding the SYSTEM tag causes that cache to be reset and regenerated.

0
Comment actions Permalink

I just had a similar phenomenon using CLion 2019.1.2

I had added cpp files to a pure c project. That caused inspections on the file not to work correctly.

Thus, two bugs that lead to the phenomenon:

* it defaults to adding cpp instead of c files in pure c projects

* the inspections don't really get that the cpp files need to be ignored, as cmake does.

That's it, the include mechanism and the inspections for proper c files all work just fine, these two together create the inspection issue.

Cheers!

0

Please sign in to leave a comment.

Have more questions?

Submit a request