Force Compile of Files

I am trying to use VEXCode text in conjunction with GitHub Desktop so that my teammates can collaborate easily on the code. However, when I attempt to compile and download code onto the robot, the compiler doesn’t seem to recognize when a file has changed. I’m assuming with the multiple file system, the compiler doesn’t send every file to the processor every time if is has not been changed. This seems to be a problem caused by the downloading and uploading of the code files to GitHub. I have found a partial fix to this by renaming the file that I have changed and it ends up compiling. However, I am looking for a better way to ensure that the compiler recognizes when a file has been changed. Does anyone have any ideas?

VEXcode should have no issues working with files under version control. VEXcode uses “make” as the program that determines what needs to be rebuilt, make primarily uses the file time and date to determine if it needs recompiling.

VEXcode also has a “file watcher” running in the background, if a different version is checked out, VEXcode should update the contents of the editor to reflect any changes or show a dialog if the file is not saved.

3 Likes

The version checker doesn’t seem to be realizing when a file has been changed, it says in the console “make: no changes to be done for ‘all’” Is there a way to fix this problem?

If a file has changed in your github repo, and you do a git pull, the date on the file should be more recent than the last build and make will rebuild the project. Are you files in the “src” or “include” folders ? does the date change when you pull changes ? It’s really nothing at all to do with VEXcode, make is an external program, I use make with files under version control every day.

1 Like

Is there a way to reset make so that it will compile everything again regardless of changes?

delete the project build folder, or update the makefile rules.

I assume you do not have the build folder under version control, VEXcode creates a .gitignore file when a new project is created that should exclude it, but if you placed build and output binaries under verison control, that would confuse make.

1 Like

Do you want me to send the file so that you can see the build files?

I tried deleting the build file, but it only recompiles main.cpp, it doesn’t compile the other included files. Is it possible that the other files are not included in the filechecker and only updates when the file is renamed?

yea, zip up the folder and either send to me DM or attach here.

TL;DR
source code (.cpp) should be in the “src” folder, header files (.h) should be in the “include” folder.

The root cause of the problem that @ceak had was project structure, .cpp files should only live in the src folder, they should not be treated like headers and included in other .cpp files. Lets look a bit at the infamous makefile and explain what it does. The makefile and other related build files are hidden by default in a new VEXcode installation, they can be shown by checking “show build files” in the preferences panel.

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)

OBJ = $(addprefix $(BUILD)/, $(addsuffix .o, $(basename $(SRC_C))) )

# location of include files that c and cpp files depend on
SRC_H  = $(wildcard include/*.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

a makefile uses a series of rules to decide how to build a project. The default target is “all”, we have a rule in the makefile that explains what the dependancies when building “all” are.

# build targets
all: $(BUILD)/$(PROJECT).bin

$(BUILD) and $(PROJECT) are macros that get expanded when make runs into a directory path. $(PROJECT) is the name of your project, we pass it from VEXcode when we call make. If I’m working on a project called “myproject” then that line would be expanded by make to be;

# build targets
all: build/myproject.bin

myproject.bin is the final output of building the project, the actual file that gets sent to the V5 brain.

Other rules we have are in mkrules.mk, they are a bit more standardized, but in summary

myproject.bin would depend on myproject.elf

myproject.elf depends on all of the .o (object) files.
this is the linking step

the .o files depend on the .c and .ccp (source code) files and also all .h (header) files.
this is the compiling step, the source .cpp files are compiled into .o files

The makefile creates a list of files to be used in the build. It considers the src folder and one additional level of sub directory inside that and looks for all .c and .cpp files. Theses lines in the makefile do that

# 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)

It looks in the include folder for header files.

# location of include files that c and cpp files depend on
SRC_H  = $(wildcard include/*.h)

it does a few other things, but we can skip those.

This was the original project structure that the OP had.
image

The file Autonomous.cpp, as an example, would not be compiled and also not used as a dependancy of other source files as it does not have a .h extension (ie. it’s not a header file). These files should live in the src folder and not be treated like headers and included in other .cpp files.

This is a revised project structure that plays nicely with our default makefile.

image

one new file was added that has global motor and other vex class instances.

more information in this topic on how to use globals and functions defined over several files

4 Likes