VEXCode "Undefined Reference"

Hello,
I am having trouble with VEXCode such that everything is showing no errors, but when I build it says “undefined reference to [function]” for all of the functions in the API I have constructed

my prelude.h

#ifndef VEX_H
#define VEX_H
#include "vex.h"
#endif

#ifndef TANKJOYSTICK
#define TANKJOYSTICK
#include "WhoopAPI/includes/Calculators/tank-joystick.h"
#endif

#ifndef PIDOBJECT_H
#define PIDOBJECT_H
#include "WhoopAPI/includes/Calculators/pidObject.h"
#endif

#ifndef C_MAP
#define C_MAP
#include "WhoopAPI/includes/Calculators/controller-mapping.h"
#endif

#ifndef DRIVEOBJECT
#define DRIVEOBJECT
#include "WhoopAPI/includes/Robot/drivetrain-object.h"
#endif

#ifndef SIMPLEPID
#define SIMPLEPID
#include "WhoopAPI/includes/Drive_Auto_Algorithms/simple_pid.h"
#endif

#ifndef INTAKE_OBJECT
#define INTAKE_OBJECT
#include "WhoopAPI/includes/Robot/intake_object.h"
#endif

#ifndef LIFTOBJECT
#define LIFTOBJECT
#include "WhoopAPI/includes/Robot/lift_object.h"
#endif

#ifndef VECTOR
#define VECTOR
#include <vector>
#endif

I believe this may have to do with scoping, but I’m not sure. I tried moving the source files into src and yet it still had the same issue. The IDE is giving an “all clear” while the compiler is throwing errors while building. Is there anything I need to do to make this work?

Could this possibly have to do with the makefile?

1 Like

Maybe I don’t know anything or maybe you don’t have any problems. That’s what it says, after all:

I managed to get this error to occur by not actually defining the function in the class, just by prototyping it:

struct CauseErr {
    void err();
};

Then later, I would declare an object and call err

CauseErr e;
e.err();

This would cause:
main.cpp:(.text.main+0x10): undefined reference to `CauseErr::err()’

Here’s what I think the problem is:
All the files included in prelude.h are just class definitions with only prototype functions. I found a weird bug in VexCode where .cpp files anywhere in the “include” directory were not compiled and files in the “src” directory that were more than one directory in were also not compiled. So a file “src/source/Calculators/pidObject.cpp” would not be compiled, whereas “src/Calculators/pidObject.cpp” would be compiled.

In short, moving all the directories and files inside the “source” directory to the “src” directory should cause a good compilation.

4 Likes

That’s not a bug. If you deviate from the structure of the template project, you need to modify the makefile to explain to the build system the structure of your project.

6 Likes