1

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 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"

Implementation of what I'm trying to include:

Implementation of what I'm trying to include

And as you can see, it does not detect it:

And as you can see, it does not detect it

Now, this is the setup of my project:

  1. 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.
  2. I've set a CMakeLists.txt file that runs on MinGW environment. This is the full content of that file:

    This is the full content of that file

  3. 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?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
  • Usually IDEs tend to resolve types only after you compile inside the IDE. – balki Mar 14 '19 at 22:08
  • 1
    I can't compile it since I don't have the source. I only have these files which describe the classes. Can't it interpret on it's own? – user10796940 Mar 14 '19 at 22:09
  • Are you creating some project with custom code at all or are you just viewing some files of another project without using them? 1. Try to create a simple `main.cpp` file with a `main` method printing "Hello World" in this same project. 2. Add the executable to CMakeLists.txt like in my answer below and see if you can run it. 3. If it works, try to include some of the files you want to use and see if they can be used successfully. Atleast you should get some compiler/linker/syntax errors indicating what is wrong. – Snackoverflow Mar 14 '19 at 22:15
  • 1
    These files are not from another project. They are just files within a folder I declared as my project. These are not directly c++ but their format is, so I wonder if there is a way CLion sees them as a regular c++ file, which will enable me to use code completion and all of that. – user10796940 Mar 14 '19 at 22:20
  • Did CLion give you any notifications (bottom-right corner) about tool-chains? See if MinGW and CMake are configured correctly in `Settings -> Build, Execution, Deployment -> Toolchains`. – Snackoverflow Mar 14 '19 at 22:28
  • 1
    Yep. Everything is fine withe toolchain, and everything is also fine when I create a normal c++ project. Which means the setup of my project, along with the hps files, are wrong probably. Btw, I did not add the hps files to the libraries. Idk how to do it – user10796940 Mar 14 '19 at 22:32
  • CLion does not really need any additional project setup. You just need to have the `CMakeLists.txt` file contents right IMO. Check that your root project directory is correct, containing the `CMakeLists.txt` and the directory `script` which you want to use. But I am guessing you need a target with `add_executable` or `add_library` in `CMakeLists.txt`. – Snackoverflow Mar 14 '19 at 22:36
  • 1
    Well the thing is, is that idk how to set it up right for my specified use – user10796940 Mar 14 '19 at 22:37
  • Depends on your purpose, are you creating an executable file or a library to be used by another project? – Snackoverflow Mar 14 '19 at 22:38
  • If you don't have it set up correctly, you should see this message on top of the `.hps` file that you are editing: `This file does not belong to any project target, code insight features might not work properly.` – Snackoverflow Mar 14 '19 at 22:40
  • 1
    I'm not creating an executable file. To say it simply, all I want to create is a project which lets me to edit these hps script with code completion and intellisense, I don't even want or need to build the project afterwards. And for that I need to set up the cmake file to find include paths for the hps files, correct? And I do no get such message – user10796940 Mar 14 '19 at 22:43
  • You can create a new project (which you said worked for you), then move the `script` directory and everything else you need into that new project's directory. But you need to add each file that you want to `#include` from the `script` directory *also* to the project target. – Snackoverflow Mar 14 '19 at 22:43
  • 1
    That could work, I'll try it. – user10796940 Mar 14 '19 at 22:44
  • @user10796940 Okay, the code insight features will work if you specify a project target in `CMakeLists.txt`. Do: `add_library(YourProjectName STATIC script/a.hps script/b.hps script/c.hps script/etc.hps)`. – Snackoverflow Mar 14 '19 at 22:45
  • 1
    It gives me these errors: CMake Error: Cannot determine link language for target MyProject. CMake Error: CMake can not determine linker language for target: MyProject – user10796940 Mar 14 '19 at 22:50
  • I honestly have no idea. I am guessing you must search for that error in google :/ – Snackoverflow Mar 14 '19 at 22:57
  • 1
    Oh well. Thanks for your help though, I appreciate it! – user10796940 Mar 14 '19 at 22:59

1 Answers1

0

Syntax Errors

Is it possible that you have Power Save Mode activated from the File menu? If it is activated, some code-parsing features may be disabled.

File Type .hps

I am guessing you already have the file type .hps registered as a C/C++ file in Settings -> Editor -> File Types. If not, you should register it!

CMakeLists

You might need to configure some more properties like the project name and a target to associate the project with the files you are using.

cmake_minimum_required(VERSION 3.12)
project(YourProjectName VERSION 0.1.0)

include_directories(script/agents)
include_directories(script/areas)
include_directories(script/base)

add_executable(YourProjectName main.cpp header1.hpp source1.cpp path/to/header2.hpp path/to/source2.cpp)

If you are not building an executable, but a library, you might need to use add_library instead. For the syntax you can check the documentation.

I hope this helps!

Snackoverflow
  • 5,332
  • 7
  • 39
  • 69
  • 1
    I made the following script: https://pastebin.com/zcKv8kyT But I get these errors: https://pastebin.com/4d1b8XY9 – user10796940 Mar 15 '19 at 13:01
  • Maybe this article will help you: https://answers.ros.org/question/218015/problem-in-determining-a-link-language-while-using-external-libraries/ – Snackoverflow Mar 15 '19 at 14:49
  • There is an answer here to solve your *linker language* errors: https://stackoverflow.com/a/16669141/2237467 .. You need to add `set_target_properties(MyTarget PROPERTIES LINKER_LANGUAGE CXX)` after your target declaration, where `MyTarget` is your library/executable name which you specified like this: `add_executable(MyTarget file1.hps file2.hps ...)` – Snackoverflow Mar 22 '19 at 23:48