CLion index does not allow some inclusion in the project directory

I have a CLion C ++ project that has the following structure:

project ---->my_includes | ----> my_own.hpp ---->source ----> my_app ----> my_src.cpp 

The first line is my_src.cpp

 #include "my_includes/my_own.hpp" 

I use an external build system that requires this inclusion format. The problem is that if I use the function in the source file indicated in the included header, CLion says "I can not find my_own.hpp" if I try to hover over the inclusion.

I tried marking the include directory containing the project source or headers, but this does not fix it. Any ideas?

+12
source share
2 answers

You need to create CMakeLists.txt so that CLion is happy. It is enough to declare all the source files, you do not need to convert your scons (or any other build system) to cmake.

You don’t even need to write CMakeLists.txt manually, you can ask CLion to do this:

  • File | New CMake Project from Sources... File | New CMake Project from Sources... (since CLion 2019.2)
  • File | Import project ... | (old CLion)

and then specify the directory containing your project.

Now edit the generated CMakeLists.txt and add the cmake command to tell CLion where to look for inclusions (in fact, to tell the compiler, and CLion will reuse this information).

Since your source files use include as #include "my_includes/my_own.hpp" , you must specify cmake the base directory containing the my_includes directory:

 include_directories(.) 

Where dot means the same directory as the directory containing CMakeLists.txt .

I tested a project reproducing your layout and from my_src.cpp I can go to my_own.hpp .

Then for assembly you still have to use scons in the console. You can also add the cmake command, add_custom_target() , which will call your scons (or your make, or whatever) so that you can also go from CLion to build errors.

+22
source

This should be a CMake-based project that will open correctly in CLion. Check out the CMake basics guide if you're new to CMake: https://www.jetbrains.com/help/clion/2016.1/quick-cmake-tutorial.html

0
source

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


All Articles