CLion cannot detect classes from sources, and does not have intellisense / code completion

Answered

Hello, this is probably a strange problem, but bare with me.

I'm using CLion so I can (hopefully) have the ability to:

  1. Have code completion for a file type that is registered as a c++ file (In my case the file type is called .hps)
  2. Make full use of the error hightailing features and all of the intellisense on my .hps files
  3. 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.

1
4 comments

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.

0
Avatar
Permanently deleted user

I made the following cmake script, but I get errors. (At the end of this script)

cmake_minimum_required(VERSION 3.12)
project(SOMA)

set(HPS_API /hps_api.hps)
set(SCIPR_DIR /script)
set(CMAKE_CXX_STANDARD 14)

file(GLOB HpsSources *.hps)

include_directories(${SCRIPT_SOURCE_DIR}/agents)
include_directories(${SCRIPT_SOURCE_DIR}/areas)
include_directories(${SCRIPT_SOURCE_DIR}/base)

add_library(agents_library ${HpsSources})

find_library(${agents_library} hps_api.hps)

add_executable(SOMA test.hps)
target_link_libraries(SOMA agents_library)

CMake Error: Cannot determine link language for target "agents_library".
CMake Error: CMake can not determine linker language for target: agents_library
CMake Error: CMake can not determine linker language for target: SOMA
CMake Error: Cannot determine link language for target "SOMA".
0

Try changing 

project(SOMA)

to

project(SOMA CXX)

and reload the CMake project.

Or you can also try adding the following lines:

set_target_properties(agents_library PROPERTIES LINKER_LANGUAGE CXX)

set_target_properties(SOMA PROPERTIES LINKER_LANGUAGE CXX)
0

Note that you do

set(SCIPR_DIR /script)

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:

file(GLOB_RECURSE HpsSources ${PROJECT_SOURCE_DIR}/*.hps)
0

Please sign in to leave a comment.