Help with several files, undefined references, and exit code error

Hello forum, I followed a code created by team 2880E (Code) for Odometry/PID, and made my own similar version in the vexcode v5 program. I split the code into separate created files, same as 2880E. I have no problems in the problems terminal, and all of the logic and programming seems correct to me, but when I try and build or download the program, I get the following:

[info]: Saving Project ...

[info]: Project saved!

windows build for platform vexv5

"LINK build/Odometry.elf"

build/src/chassis-control.o: In function `drivePID()':

chassis-control.cpp:(.text._Z8drivePIDv+0xc): undefined reference to `yPosGlobal'

chassis-control.cpp:(.text._Z8drivePIDv+0x10): undefined reference to `yPosGlobal'

chassis-control.cpp:(.text._Z8drivePIDv+0x28): undefined reference to `xPosGlobal'

chassis-control.cpp:(.text._Z8drivePIDv+0x2c): undefined reference to `xPosGlobal'

build/src/chassis-control.o: In function `chassisControl()':

chassis-control.cpp:(.text._Z14chassisControlv+0x94): undefined reference to `xPosGlobal'

chassis-control.cpp:(.text._Z14chassisControlv+0x9c): undefined reference to `xPosGlobal'

chassis-control.cpp:(.text._Z14chassisControlv+0xa8): undefined reference to `yPosGlobal'

chassis-control.cpp:(.text._Z14chassisControlv+0xac): undefined reference to `yPosGlobal'

build/src/chassis-control.o: In function `_GLOBAL__sub_I_chassis_control.cpp':

chassis-control.cpp:(.text._GLOBAL__sub_I_chassis_control.cpp+0x0): undefined reference to `xPosGlobal'

chassis-control.cpp:(.text._GLOBAL__sub_I_chassis_control.cpp+0x8): undefined reference to `xPosGlobal'

chassis-control.cpp:(.text._GLOBAL__sub_I_chassis_control.cpp+0x14): undefined reference to `yPosGlobal'

chassis-control.cpp:(.text._GLOBAL__sub_I_chassis_control.cpp+0x18): undefined reference to `yPosGlobal'

build/src/main.o: In function `pre_auton()':

main.cpp:(.text._Z9pre_autonv+0x10): undefined reference to `Inertial6'

main.cpp:(.text._Z9pre_autonv+0x18): undefined reference to `Inertial6'

main.cpp:(.text._Z9pre_autonv+0x38): undefined reference to `Inertial6'

main.cpp:(.text._Z9pre_autonv+0x3c): undefined reference to `Inertial6'

main.cpp:(.text._Z9pre_autonv+0x5c): undefined reference to `Inertial6'

build/src/main.o:main.cpp:(.text._Z9pre_autonv+0x60): more undefined references to `Inertial6' follow

build/src/main.o: In function `autonomous()':

main.cpp:(.text._Z10autonomousv+0x24): undefined reference to `STrack'

main.cpp:(.text._Z10autonomousv+0x28): undefined reference to `STrack'

build/src/draw-field.o: In function `drawField()':

draw-field.cpp:(.text._Z9drawFieldv+0x2c0): undefined reference to `xPosGlobal'

draw-field.cpp:(.text._Z9drawFieldv+0x2c4): undefined reference to `yPosGlobal'

draw-field.cpp:(.text._Z9drawFieldv+0x2c8): undefined reference to `xPosGlobal'

draw-field.cpp:(.text._Z9drawFieldv+0x2cc): undefined reference to `yPosGlobal'

draw-field.cpp:(.text._Z9drawFieldv+0x50c): undefined reference to `xPosGlobal'

draw-field.cpp:(.text._Z9drawFieldv+0x514): undefined reference to `xPosGlobal'

draw-field.cpp:(.text._Z9drawFieldv+0x53c): undefined reference to `yPosGlobal'

draw-field.cpp:(.text._Z9drawFieldv+0x544): undefined reference to `yPosGlobal'

build/src/odometry.o: In function `positionTracking()':

odometry.cpp:(.text._Z16positionTrackingv+0xb0): undefined reference to `Inertial6'

odometry.cpp:(.text._Z16positionTrackingv+0xb8): undefined reference to `Inertial6'

odometry.cpp:(.text._Z16positionTrackingv+0x2b8): undefined reference to `xPosGlobal'

odometry.cpp:(.text._Z16positionTrackingv+0x2bc): undefined reference to `yPosGlobal'

odometry.cpp:(.text._Z16positionTrackingv+0x2c0): undefined reference to `xPosGlobal'

odometry.cpp:(.text._Z16positionTrackingv+0x2c4): undefined reference to `yPosGlobal'

odometry.cpp:(.text._Z16positionTrackingv+0x2fc): undefined reference to `Inertial6'

odometry.cpp:(.text._Z16positionTrackingv+0x304): undefined reference to `Inertial6'

make: *** [vex/mkrules.mk:18: build/Odometry.elf] Error 1

[error]: make process closed with exit code : 2

Here is my code. I had an error importing it to vexforum, so I put it all on a google doc (sorry :frowning: ) with the name of the file in white at the top of each section.

my code

I am not super concerned with the undefined references because I believe my include files are correct and they don’t seem to cause errors, though I am still not 100% sure why the program has the undefined references. I am not sure about the last 2 lines. The error says that I need to make process closed with exit code, and doesn’t reference where the error was. I went through and couldn’t find anywhere that had this error. I am not overly familiar with creating multiple files in C++ and including them between files, so I believe I most likely messed up somewhere along the way with one of the files including headers or something like that.

I was wondering if someone could look through my code and see if they see any include errors, or any problems of why my code wont compile. I am not worried about the odometry or code itself, I just want to get it running, then I can work on the odometry and edit the code. Thanks everyone in advance, and sorry if its confusing. Thanks again,
-Jack

  1. the inertial definition in robot-config.cpp does not match the one in robot-config.h. Change it to Inertial6 instead of inertial6
  2. remove sTrack from line 154 of main
  3. you declare but never define x and y pos global. add the following lines to the top of odometry.cpp to define them
double xPosGlobal = 0;
double yPosGlobal = 0;
1 Like

That did it, thank you! The inertial part and the removal of sTrack was just me not proofreading hard enough lol, I didn’t realise I needed to define them even if I had them in a header file. Again, thank you!

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