How to add an include directory to C++ project?

I have spent many hours on this basic issue and can’t figure it out. I have added a directory to our C++ project that has both src and include (to support a camera). for the life of me, I can’t get VS to compile a CPP with a .h from the include directory.

I’d love some basic steps on how to do this. In a normal world, adding a “-I” with dir to the makefile would do the job.

I have tried many variations of adding directories to c_cpp_properties.json and NONE work. Compilation still can’t find the include dir.
“configurations”: [
“name”: “Win32”,
“includePath”: [

I found one post that says that the c_cpp_properties.json file is not needed and can be deleted:

If that is the case, where do I put my include directory in the VS configuration?
thanks !!

If I understand your question properly, you have created a class in a header(h/hpp) and source (cpp) and are confused how to use them in your robot class?

As you can see in my pic, put your cpp in src/main/cpp and header file in src/main/include.

Then you just #include your header file in the robot.h or other file as appropriate.

Your code should be in src/main/cpp and src/main/include, but you can change these paths my modifying those entries in your build.gradle

Thanks for the responses! All right, we’ve made some progress we can share (user redmonke and bothacker are on the same team #509 laptop).

Let us clarify what we are doing. We already had the baseline robot image building and working. We successfully added some Commands and a Command Group per the WPIlib guidelines. Now we are integrating the pixy2 camera code and this phase is what gave us the difficulty. We did not want to dump all the pixy2 support code into the main directory and wanted to keep the bulk of the pixy2 directory provided from their git repo as-is.

Here are some general steps that may help others …

(1) We made a pixy2 source directory and put one of the main pixy2 files into it. VS was good with understanding that this dir contained files that needed to be compiled in. We used right-click “New Folder” to add this.


(2) We used intellisense to add the linux directories for the base C++ dependencies like stddef.h. Hover over the lightbulb, select add to the properties file. VS put these into the c_cpp_properties.json file. HOWEVER, our attempts at adding the pixy2 include directories manually to this json file did not work, a painful lesson.

(3) As Jaci suggested, we found that adding the pixy2 include directories to build.gradle got them into the system build. Many hours needed to figure this out!! Now we can keep the pixy2 directory structure from git as-is, a big win.


In theory these steps could be generalized to add other 3rd party code that is not packaged nicely.

We are past the compilation phase and now working on the link phase. We now have an external dependency on the USB library to deal with.

Here is a link we found useful to understand some of the Intellisense rules and c_cpp_properties.json file content:

thanks for the responses!

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.