CLion cannot detect classes from sources, and does not have intellisense / code completion
已回答
Hello, this is probably a strange problem, but bare with me.
I'm using CLion so I can (hopefully) have the ability to:
- Have code completion for a file type that is registered as a c++ file (In my case the file type is called .hps)
- Make full use of the error hightailing features and all of the intellisense on my .hps files
- Be able to use classes from other hps files, located in different folders in my project.
- The general c++ style coloring is working, however, CLion won't notify me about syntax errors inside hps files:

- CLion won't find the source files I include, and therefore won't detect any classes that are declared inside other hps files and their methods (all of the folders that include that hps files are located inside a folder named "script":


Now, this is the setup of my project:
- My project is located and opened at folder that has a folder inside it called "script" in which all of the .hps files I include are there.
- I've set a CMakeLists.txt file that runs on MinGW environment . This is the full content of that file:

- There is a file, in my PARENT folder, called hps_api.hps, that consists classes declarations as well. Note that CLion won't detect it as well.
Did I do something wrong? The only thing I pretty much did was to add include directories to the cmake file, but I guess it's not enough?
In another program called CodeLite for example, it's possible to just add to a list a path to search files to include, and then CodeLite parses those files and I can go to declarations of classes without any problems. Surely it's possible with CLion as well, right?
Thanks for your help.
请先登录再写评论。
Hello!
CLion uses a concept of a project and relies on CMake (in your case) as a build system for it. All the includes paths, variables and more is taken from CMake files and are used by CLion to understand your project better and to resolve your code correctly.
In your CMakeLists.txt you don't have any build target, therefore none of your files are considered as a part of the project and code insight features don't work for them. You need to create a build target and add your files to it. We have a quick CMake tutorial in our web help, please see: https://www.jetbrains.com/help/clion/quick-cmake-tutorial.html.
I made the following cmake script, but I get errors. (At the end of this script)
Try changing
to
and reload the CMake project.
Or you can also try adding the following lines:
Note that you do
and then use a different variable ${SCRIPT_SOURCE_DIR} which is not set anywhere.
And the
find_library(${agents_library} hps_api.hps)line is not needed.And, just in case, about
file(GLOB HpsSources *.hps): note that if you want CMake to recursively scan a given directory, you need to use GLOB_RECURSE - https://cmake.org/cmake/help/latest/command/file.html#glob-recurse. Like this: