Having trouble with subsystem headers in PROS

I’ve had this problem for a while and been just throwing my headers into my (ROOT)/include directory as the solution - this works but is very messy.
NOTE: this is ONLY my headers - okapi, display, etc all compile fine.
I’m not very experienced in cpp and very inexperienced with larger projects.I looked at the Makefile and it looked like they were set up to include everything in subdirectories of include. The line that stood out to me was

TEMPLATE_FILES=(INCDIR)/**/*.h (INCDIR)/**/*.hpp

This looks to me like it should include every header with .h or .hpp in any subdirectory of include?
The error seems to be raised in common.mk which to me means nothing but might be helpful. I tried looking through common.mk but I don’t understand any of it. If it helps - I have not changed anything in Makefile or common.mk since creating the project.

I also tried explicitly adding “$(ROOT)/include/subsys” and failed (granted I may have (and probably did) do this wrong).

The directories look the same as on creation of the project with the exception of a subsys directory in include and src which each hold my .hpp and .cpp files.
Any help would be greatly appreciated.

would help if you could post the error and what commands you’re running too

2 Likes

What I see teams do is add their subsystem includes to main.h toward the end of the file, where the line

//#include <iostream>
#include "subsys/bruh0.hpp" //for example
#include "subsys/bruh1.hpp"

is by default.
But I just directly put those relative includes in whatever cpp files need them.

Check out this section on learncpp.com to learn more about header files.

1 Like

This worked, thanks.
I knew this was an option but when I tried I don’t think I gave syntastic enough time to update so they were still highlighted and I undid the change assuming it didn’t work.
This doesn’t answer the question of why the Makefile doesn’t cover it but I can look into that more in my own time.

It may be possible for the Makefile to cover it by using EXTRA_CXXFLAGS or something similar.

When using g++ directly, the -I argument is used with a file path to add include directories.

You could try adding -I$(ROOT)/include/myIncludesDir to either:

Makefile
INCDIR=$(ROOT)/include

WARNFLAGS+=
EXTRA_CFLAGS=
EXTRA_CXXFLAGS=-I$(ROOT)/include/myIncludesDir

# Set to 1 to enable hot/cold linking
USE_PACKAGE:=1

or

common.mk
DEVICE=VEX EDR V5

MFLAGS=-mcpu=cortex-a9 -mfpu=neon-fp16 -mfloat-abi=softfp -Os -g
CPPFLAGS=-D_POSIX_THREADS -D_UNIX98_THREAD_MUTEX_ATTRIBUTES -I$(ROOT)/include/myIncludesDir
GCCFLAGS=-ffunction-sections -fdata-sections -fdiagnostics-color -funwind-tables

WARNFLAGS+=-Wno-psabi

or

common.mk
ASMFLAGS=$(MFLAGS) $(WARNFLAGS)
CFLAGS=$(MFLAGS) $(CPPFLAGS) $(WARNFLAGS) $(GCCFLAGS) --std=gnu11
CXXFLAGS=$(MFLAGS) $(CPPFLAGS) $(WARNFLAGS) $(GCCFLAGS) --std=gnu++20  -I$(ROOT)/include/myIncludesDir
LDFLAGS=$(MFLAGS) $(WARNFLAGS) -nostdlib $(GCCFLAGS)
SIZEFLAGS=-d --common
NUMFMTFLAGS=--to=iec --format %.2f --suffix=B

One of them is bound to work. Also you might have to add a space like

-I $(ROOT)/include/myIncludesDir

but maybe not. I haven’t tested it, you will probably have to tinker with it a little to get it working how you want.

After that is properly done, you should be able to include the file you want without a relative path:

#include "myHeader.hpp"

See the comment above TEMPLATE_FILES, it looks like that is meant for people creating PROS libraries:

# files that get distributed to every user (beyond your source archive) - add
# whatever files you want here. This line is configured to add all header files
# that are in the the include directory get exported
TEMPLATE_FILES=$(INCDIR)/**/*.h $(INCDIR)/**/*.hpp

Also, users are not really intended to edit common.mk I think it might get overwritten by PROS updates.

2 Likes

ok i think i see what you were going for now. This line:

is for specifying files that will be included with a template should you choose to make and distribute one.

by default, the makefile will in fact allow you to #include "header.h" if the following conditions are satisfied:

  • header.h is located in include/some_subdir
  • the source file including header.h is in src/some_subdir

this is defined in common.mk, lines 255 and 265:

$(INCLUDE) -iquote"$(INCDIR)/$$(dir $$*)"

the definition of INCLUDE is on common.mk, line 37:

INCLUDE=$(foreach dir,$(INCDIR) $(EXTRA_INCDIR),-iquote"$(dir)")

as you can see, any directory specified in INCDIR and EXTRA_INCDIR are passed to the compiler with -iquote. INCDIR is defined in the default Makefile on line 13 so if you want to make the things in include/subsys generally accessible to the rest of your project without having to specify the relative path, you can either place it there directly or else define EXTRA_INCDIR. (an example of the latter is the PROS kernel)

hope this helps, and sorry for misunderstanding your original post

5 Likes