Undefined reference to object not on line (PROS)

I have been trying to compile my code, and it results in this output:

Creating cold package with libc,libm,libpros,okapilib [OK]
Stripping cold package  [DONE]
Section sizes:
   text    data     bss   total     hex filename
1.32MB  4.36KB  47.66MB  48.97MB 30f83bc bin/cold.package.elf
Compiled src/auton.cpp [OK]
Compiled src/autonmethods.cpp [OK]
Compiled src/globals.cpp [OK]
Compiled src/main.cpp [OK]
Adding timestamp [OK]
Linking hot project with ./bin/cold.package.elf and libc,libm,libpros,okapilib [ERRORS]
c:/program files/pros/toolchain/usr/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld.exe: bin/main.cpp.o: in function `opcontrol':
C:\Users\mcurn\OneDrive\Documents\GitHub\6210M-Over-Under/src/main.cpp:70: undefined reference to `mIntake'
collect2.exe: error: ld returned 1 exit status
make: *** [common.mk:239: bin/hot.package.elf] Error 1
ERROR - pros.cli.build:make - Failed to make project: Exit Code 2
Error: Failed to build```

Here is line 70:
if(selectionIndex > 1) selectionIndex = 0;

If that line is commented out, a similar error is thrown complaining about line 93, which has a similar command to line 70 on it. If this is commented out as well, it claims there is an undefined reference to mIntake on line 203, a line that only holds a single curly bracket }.

The only lines in main.cpp that reference mIntake are lines 161-167:

if(master.get_digital(DIGITAL_R1)){
mIntake = 127;
} else if(master.get_digital(DIGITAL_R2)){
mIntake = -127;
} else{
mIntake = 0;
}

If these lines are commented out, the program builds just fine. Any ideas on how to fix this?

Do you have a line before line 70 but within the opcontrol function that declares the variable mIntake?

Should be something like:

void opcontrol() {
  int mIntake = 0;
  // The rest of your stuff
}

mIntake is a reference to a motor, which is declared in a globals.cpp file, externed in a globals.h file, and subsequently included in the main.cpp file

Motor declaration in .cpp:

pros::Motor mINTAKE(INTAKE, pros::E_MOTOR_GEARSET_06, false, pros::E_MOTOR_ENCODER_ROTATIONS);

Motor extern line in .h:

extern pros::Motor mIntake;

I have confirmed that globals.h is included in main.cpp and there is an include guard on the globals .h file that appears as so:

#ifndef _GLOBALS_H_
#define _GLOBALS_H_
// code
#endif // _GLOBALS_H_

mIntake and mINTAKE are not the same thing, variables are case sensitive.

7 Likes

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