[C++] #include errors


Our programming team has run into some issues using C++ with Visual Studio. This is our first year using C++ and we’ve come across a bunch of #include errors. Every #include has errors, and they usually all say cannot open source file *filename.h*. We’ve tried searching for these errors on Google, but the “fixes” are way too complicated for us and seem like they’re not what we’re looking for. The issue has occurred on 3 separate Windows 10 laptops. (Sorry if this is the wrong place, but this is kind of driving us all nuts.)

Can you provide us with a snippet with your code? We can’t find out whats wrong with your code if we don’t have it

The error occurs with any and all code using #include. We’re using some examples, though.
/* Copyright © 2017-2019 FIRST. All Rights Reserved. /
Open Source Software - may be modified and shared by FRC teams. The code /
must be accompanied by the FIRST BSD license file in the root directory of /
the project. /

#include <frc/GenericHID.h>
#include <frc/Spark.h>
#include <frc/TimedRobot.h>
#include <frc/XboxController.h>
#include <frc/drive/DifferentialDrive.h>


  • This is a demo program showing the use of the DifferentialDrive class.
  • Runs the motors with split arcade steering and an Xbox controller.
    class Robot : public frc::TimedRobot {
    frc::Spark m_leftMotor{0};
    frc::Spark m_rightMotor{1};
    frc::DifferentialDrive m_robotDrive{m_leftMotor, m_rightMotor};
    frc::XboxController m_driverController{0};

void TeleopPeriodic() {
// Drive with split arcade style
// That means that the Y axis of the left stick moves forward
// and backward, and the X of the right stick turns left and right.

int main() { return frc::StartRobot(); }

A likely possibility is that the source files you are trying to include are not in a directory that the project has marked to include as sources. One option is to put the source files in your project source folder. Another option is to add a directory to the “include directories” section of the project settings.

The thing is, though… We do not know how to do that. We tried using “>WPILib C++: Refresh C++ Intellisense” and that seems to temporarily fix it. There aren’t any #include errors until we restart VSCode. Is this something that’ll work and we just have to run that command every time? Or is there an easier, more convenient way to do that?

(Keep in mind: we’re still VERY new to this, and we appreciate your assistance.)

I have a disclaimer of my own: I’ve never programmed an FRC robot, and I am only somewhat familiar with C++, having only used it for a couple classes in college and some small personal projects.

That said, I just installed WPILIB fresh on my VSCode, and I found that while the IDE shows errors for “cannot open source file…”, a build (WPILib: Build Robot Code) was all that was needed to get rid of the errors. Can you paste the terminal output that happens when you try to build?

> Executing task: gradlew build generateVsCodeConfig   -Dorg.gradle.java.home="C:\Users\Public\wpilib\2020\jdk" <

5 actionable tasks: 5 up-to-date

Are you still seeing the errors?


See the thread on intellisense issues. @Thad_House provided steps about how to fix those annoying issues. Here is a link to that thread:

So if your build is succeeding, what are the errors blocking? According to the link provided by @wits the warnings shouldn’t prevent code from deploying/running.

Well, the link @wits provided fixes it temporarily, but perhaps it’s just a visual thing we’ll have to deal with. I’ll do some testing tomorrow with our robot and see if the errors actually prohibit us from doing anything and I’ll keep you posted.

While there are bunch of fixes out there, our team faces that everyday without having much problem. It’s a stupid thing that just pops up very often(like a daily routine). You can check if it is actual error by pressing on ctrl and trying to click on the include file. If you can click on it and redirects you to the file, you are fine. If you can’t click on it, just try closing out visual studios and reopening it. This always seems to do the trick for us.

Unless you can’t build the code due to the error, no need to worry about it. It’s really just a fake error most of the time. And since you said it builds fine, just ignore the error. Our team just live with it.

To be honest include errors are really common especially when using visual studios and c++ however one tip that I have for you is to make sure that you close out of you editing tabs(I’m not sure what they’re actually called) before you exit out of visual studios or shut off your laptop and then when you go to open up your files again always make sure you open Robot.cpp first and don’t open it up till the the little arrow at the bottom stops spinning. I’ve found doing this drastically decreases the amount of include errors I get and I really only get them now when I forget to close out of the editing tabs.