I’ve been going through much of the learncpp tutorials, but I am having problems make what I am trying to do work (which is to make the compiler acknowledge other directories instead of just the src and include directory).
I am unsure if recognizing other directories should be automatic within vexcode, but I’m unsure about how to make it work.
you may have to edit the makefile. vexcode defaults to only supporting includes in the “include” and src folders. If you want you can put those directories in include and src and do somthing like #include "objectheaders\motorObject.h"
I am not familiar with VexCode, but in general if you want a file to acknowledge another directory, you can use an include like you have done already. When you use an include, it only looks within the same folder (src) of the file (main.cpp) you are writing it in. If you want to include motorObject.h you need to use a relative path to said file. If you follow along with the example which I linked, you should come up with the relative path "../objectHeaders/motorObject.h" The../ is needed to move one directory up from src which holds your main then your path can go to objectHeaders and so on.
for building you can update the makefile. For the intellisense, which is running a language server, it’s not really possible unless you use a more complete pathname so the language server can follow it from src or include folders.
To clarify, the only way to make it include files in other directories is to explicity identify the path of said directory in every single include for a file? (Unless in src or include directory)
There are two issues to deal with. To keep the real time intellisense happy, use the path as I show in that screen shot. You don’t have to do that if you can put up with errors being shown by the language server in the code. The language server uses the compile_commands.json file for information on where to find include files etc. This is more or less hard coded in VEXcode and it gets generated when the project is saved. Creating it based on the actual makefiles is usually what’s done by other systems, but that is also prone to errors and often has issues with finding the source of system headers, so we just kept it simple.
To have the project build, I modified the makefile as follows.
Makefile
# VEXcode makefile 2019_03_26_01
# show compiler output
VERBOSE = 0
# include toolchain options
include vex/mkenv.mk
# location of the project source cpp and c files
SRC_C = $(wildcard src/*.cpp)
SRC_C += $(wildcard src/*.c)
SRC_C += $(wildcard src/*/*.cpp)
SRC_C += $(wildcard src/*/*.c)
SRC_C += $(wildcard library_src/*.cpp)
OBJ = $(addprefix $(BUILD)/, $(addsuffix .o, $(basename $(SRC_C))) )
# location of include files that c and cpp files depend on
SRC_H = $(wildcard include/*.h)
SRC_H += $(wildcard library_inc/*.h)
# additional dependancies
SRC_A = makefile
# project header file locations
INC_F = include .
# build targets
all: $(BUILD)/$(PROJECT).bin
# include build rules
include vex/mkrules.mk
added new locations for source and header files
specifically added these two lines
SRC_C += $(wildcard library_src/*.cpp)
SRC_H += $(wildcard library_inc/*.h)
and modified this one.
# project header file locations
INC_F = include .
there are alternate ways of achieving the same thing