Tell CLion to use header include path with prefix

妖精的绣舞 提交于 2019-12-12 14:20:10

问题


I have a project layout as follows:

  • workspace
    • project_a
      • project_a -> .h files here
      • Root -> .cxx files here
    • project_b
      • project_b -> .h files here
      • Root -> .cxx files here

I cannot change the directory layout due to the build system that we're using. Headers are included as

#include "project_a/some_header.h

also from the corresponding .cxx file. I've created a CMakeLists.txt file in the root directory, that adds all my projects via include_directories(project_a project_b), which should be the path prefixed before the one given in the #include. CLion does not manage to find and index any of my files.

Additionally, I have an automatically generated directory of headers of structure

  • include
    • lib_a -> .h files
    • lib_b -> .h files

and I've set them up accordingly, but it also does not work.

Does CLion not manage to resolve the prefixed path in the #include or why is this not working?


回答1:


If the only thing that doesn't work is Clion's interpretation of your headers then you should check out the Clion FAQ. If Clion's not working the way you expect then your CMake project might not be set up correctly or you might be doing something unintentionally. You should show us your CMakeLists.txt.

From the Clion FAQ:


Q: CLion fails to find some of my headers. Where does it search for them? A: CLion searches through the same places CMake does. Set the INCLUDE_DIRECTORIES variable in CMake to provide the headers path to the IDE.

By the way, in this wiki you can find a lot of useful CMake variables with descriptions that can be especially helpful if you are new to CMake.

Q: Refactorings are not working and highlighting is wrong, even though the project can be compiled correctly. What’s happened? A: Most probably CLion is unaware of some files in your project (these files are grayed out in the project tree): non-project-files It gets this information from the CMakeLists.txt files in the following way: set(SOURCE_FILES main.cpp) add_executable(my_exec ${SOURCE_FILES}) This is how CLion now knows that main.cpp is included in your project. As for now, header files (in case their names differ from the appropriate .cpp files already added to the SOURCE_FILES variable) should also be included in the project in that way.



来源:https://stackoverflow.com/questions/36619898/tell-clion-to-use-header-include-path-with-prefix

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!