In included file: main file cannot be included recursively when building a preamble

Hey,

today, I decided to update the pros to the new version. After that, include the main.h in headings
shows as an error

when I go to the error, it shows me my including heading file

I completely don’t understand, where is the problem, cause it worked before.

Thanks for help

It may be that in 'SubSystemFiles/robot-config.hpp" you have an include statement to “main.h”.
Can you send your robot-config header file?

It looks like that

I have to include main.h. With it, I can use the pros library.

Basically, what’s happening is that in your robot-config.cpp, you’re including main.h, which is including the robot-config.hpp, which is including main.h, which includes the robot-config.hpp, etc, etc.
What you can do to fix this is either not including main.h in robot-config.hpp, or not including robot-config.hpp in main.h. In robot-config.cpp you can just #include both of them seperately.

After recreating this on my machine, VSCode does show this as an error but you should still be able to compile the program. If you don’t want the error to appear visually, you can create a file in your project’s root directory (contains Makefile, common.mk, project.pros, etc.). Name this file .clangd and put the following inside of it:

Diagnostics:
  Suppress: 'pp_including_mainfile_in_preamble'

After restarting VSCode, you should no longer see the error.

1 Like

Alright, I tried the first one, which doesn’t work. I have to include the “main.h” to use the pros library.

The second one works, but I have to include in this in another 10 files and these 10 files also include.

I cannot make make .clangd file there
image
but I interest in this solution

Interesting, I have never encountered that issue. You can open up file explorer/finder/whatever you normally use to navigate files, and create the file through that instead of VSCode.

1 Like

Which operating system are you on?

nevermind, it works. I just copied and pasted it. Then, I rewrite it

Oh also, you definitely want to use header guards for this. This will prevent your recursive inclusion problem from actually redefining everything an infinite number of times. Simply add the line #pragma once at the top of all of your header files.

2 Likes

This will be fixed in a soon to be released update.

3 Likes