Error Compiling. undefined reference to...

im fairly new to arduino and coding in C (ive only had experience in Visual Basic (not my choice)) so ive just followed a tutorial on youtube on controlling 2 servos with a joy stick. the only changes that i have made are variable names, the rest is exactly the same, yet im constantly getting multiple error messages when compiling.

the code is;

#include<Servo.h>
Servo SerX;
Servo SerY;
int JoyX = 0;
int JoyY = 1;
int JoyVal;

void setup() {
SerX.attach(3);
SerY.attach(5);
}

void loop() {
JoyVal = analogRead(JoyX);
JoyVal = map (JoyVal, 0, 1023, 0, 180);
SerX.write(JoyVal);
JoyVal = analogRead(JoyY);
JoyVal = map (JoyVal, 0, 1023, 0, 180);
SerY.write(JoyVal);
delay(15);
}

the Error messages i get are below:

C:\Users\james\AppData\Local\Temp\cctAC0Fj.ltrans0.ltrans.o: In function `handle_interrupts’:

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.21.0_x86__mdqgnx93n4wtt\libraries\Servo\src\avr/Servo.cpp:58: undefined reference to `digitalWrite’

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.21.0_x86__mdqgnx93n4wtt\libraries\Servo\src\avr/Servo.cpp:65: undefined reference to `digitalWrite’

C:\Users\james\AppData\Local\Temp\cctAC0Fj.ltrans0.ltrans.o: In function `main’:

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.21.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/main.cpp:35: undefined reference to `init’

C:\Users\james\AppData\Local\Temp\cctAC0Fj.ltrans0.ltrans.o: In function `attach’:

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.21.0_x86__mdqgnx93n4wtt\libraries\Servo\src\avr/Servo.cpp:241: undefined reference to `pinMode’

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.21.0_x86__mdqgnx93n4wtt\libraries\Servo\src\avr/Servo.cpp:241: undefined reference to `pinMode’

C:\Users\james\AppData\Local\Temp\cctAC0Fj.ltrans0.ltrans.o: In function `loop’:

C:\Users\james\Documents\Arduino\Test_1_Analogue_Servos/Test_1_Analogue_Servos.ino:15: undefined reference to `analogRead’

C:\Users\james\Documents\Arduino\Test_1_Analogue_Servos/Test_1_Analogue_Servos.ino:18: undefined reference to `analogRead’

C:\Users\james\Documents\Arduino\Test_1_Analogue_Servos/Test_1_Analogue_Servos.ino:21: undefined reference to `delay’

collect2.exe: error: ld returned 1 exit status

Using library Servo at version 1.1.3 in folder: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.21.0_x86__mdqgnx93n4wtt\libraries\Servo
exit status 1
Error compiling for board Arduino/Genuino Uno.

in the video the code works perfectly fine, and all the comments say that it works aswell so ive just got no clue it what is going wrong.

since this is a .cpp file, not .ino, do you need

#include "Arduino.h"

gciurpita:
since this is a .cpp file, not .ino, do you need

#include "Arduino.h"

The library does already have this:

I suppose it's possible that JamesC111199 modified the library and didn't mention it, but I believe Windows makes modifying things in the C:\Program Files\WindowsApps folder very difficult, so I doubt that is it.

@JamesC111199 try closing all Arduino IDE windows, start the IDE again, then try compiling again. That will clear the compilation cache and hopefully fix the problem.

If that doesn't help, try uninstalling and then re-installing the Arduino IDE.