"main.h" Not Found (Linter)

Everytime i try tp modify any new program, the program will put a error at “main.h” and say main.h not found. However in the program files, The include file has a “main.h”. Did i do something wrong?

1 Like

open terminal ,then input prosv5 build-compile-commands

This is a commonly asked question.

There is actually no error going on. It’s just the linter giving you that error because it does not have accurate information.
The linter is the utility that gives you potential compile errors as you type, before you compile. However, you should never trust it. Sometimes it breaks, sometimes it lags, sometimes it gets confused. This is not a PROS thing, this is just the nature of some linters.
Nevertheless, when the linter works, it works great.

The linter relies on information from the compiler to know where the files are. The compile process is managed by the Makefile, which is what controls the execution of the actual gcc compiler. However, the linter cannot infer information straight from the Makefile. Because of this, without intervention, how could it know where main.h is? The Makefile knows, because it knows to look in include, but the linter does not.

This is solved whenever you compile successfully. Once the compile process is complete, the Makefile script generates a big list containing the directories of all the files in your project. It saves this list in compile_commands.json. This file contains the directories of all the files in your project, along with some extra compile information.

This is the file the linter reads. With an up to date compile_commands.json, the linter will know exactly where each file is located, and how the compiler goes about compiling. Only then will it be able to give you an accurate survey of any potential errors.

Whenever you rename your project, or move files around, the linter will break, because the cache will point to non-existent files (since the paths are absolute). Recompiling will fix this.

Note: When you compile, the Makefile checks to see if you have changed any files before compiling. This saves time in the compile process. However, if you need it to regenerate the cache, be careful to make sure it actually compiles, and does not skip due to the lack of any changes to the code.
To jog it back into compiling, change a .cpp file, or run PROS->Build->All or make all.

The linter is just a tool that gives you potential errors as you type. It is separate from the compiler. It can get confused, as it requires the compiler telling the linter where everything is.
The compiler regenerates that linter cache (compile_commands.json) every time it compiles. Without an up-to-date compile_commands, the linter will not work. Not finding main.h is a linter error, not a compile error.
If you haven’t made any changes to your code between compiles, it will skip compiling. To get it to regenerate the cache, you need to make a change to the code to jog the compiler back into action. If you have a real compiler error, it won’t generate the linter cache until the compile process is successful.

I hope this clears things up for you, as well as for anyone else with this issue.


VEXcode has similar issues. We use a different linter but also rely on compile_commands.json. We cheat a little to make the linter play nicely with header files, the problem with the output of the compile process is that you do not usually compile header file directly, therefore there is usually nothing in compile_commands.json file about headers. If you open a header that assumes another header has been included in the source code first, you will see lots of errors, this would be the situation with many sdk header files that assume they are never used on their own but as part of a group. So if in doubt, build the project and trust the “real” compiler output.


However even when i build the program, the error still happens. Even when i open a brand new program the error still occurs. Btw i am using a Macbook pro

Can you actually post the output that appears in the terminal?


You need to elaborate. The error still happens in the linter, or when you compile?
Like I said, don’t trust the linter.
Like Electrobotz said, please post your error from the terminal.


As I mentioned here:

It might be because you don’t have the project folder properly open in the editor, so the linter does know even know where to look for to find compile_commands.json.
Try opening your project in a new window, with that project being the sole open folder.

1 Like

Sorry to revive an old topic, but I’m having the same issue and can’t seem to do any of the solutions I’ve read. I’m on a school Mac. The admin manually installed all pros dependencies rather than using homebrew. The terminal is very buggy and I can’t type anything in it. Running PROS->Build->All doesn’t seem to do anything. The issue may lie in the fact that this is a managed school device and PROS may not be able to install everything it needs. I also have the error use of undeclared identified 'pros' every time there is pros::. . . in the code. I am in a new project window with just the new program. I also tried opening someone else’s program and had the same issue.

Sounds like this is a bigger issue with your PROS installation, which is not really the topic of this thread. You should create a new topic to debug your installation, or hop onto discord to ask the PROS developers directly.


It could be. I ususally code on my personal laptop anyway so I honestly just don’t care enough to debug this. Thanks for the help.