CodeBlock Compiling error(Code on Anduino IDE is work)undefined reference to ...

Hello :
I'm new to arduino codeing, had Compiling error on CodeBlock IDE (Same Code on Anduino IDE is work),
I Search by Google, more "multiple undefined reference errors" case, because the required library is not linked...

I guess that may not my case..

that's my code here, any idea?

Sorry for my poor English

Thanks:-)

Wing

Totol 3 warning
ino:9: undefined reference to Servo::attach(int) ino:23: undefined reference to Servo::write(int)
ino:4: undefined reference to `Servo::Servo()'

#include "Servo.h"
#include "Arduino.h"

Servo servo;
long num;

void setup()
{
     servo.attach(9);
Serial.begin(9600);
Serial.print("Enter Position = ");
}

void loop()
{
 while(Serial.available()>0)
    {
    num= Serial.parseInt();
    Serial.print(num);
    Serial.println(" Degree");
    Serial.print("Enter Position = ");
    }
    servo.write(num);
    delay(15);
}
Cleaned "Servo- Serial Control - Simulator - Debug"

-------------- Build: Simulator - Debug in Servo- Serial Control (compiler: GNU GCC Compiler)---------------

Compiling: Servo- Serial Control.ino
Linking console executable: build\Servo- Serial Control_sim.exe
obj\Debug\Servo- Serial Control.o: In function `setup':
D:/My文件/ProgramCode - Arduino/CodeFile/Servo- Serial Control/Servo- Serial Control.ino:9: undefined reference to `Servo::attach(int)'
obj\Debug\Servo- Serial Control.o: In function `loop':
D:/My文件/ProgramCode - Arduino/CodeFile/Servo- Serial Control/Servo- Serial Control.ino:23: undefined reference to `Servo::write(int)'
obj\Debug\Servo- Serial Control.o: In function `__static_initialization_and_destruction_0':
D:/My文件/ProgramCode - Arduino/CodeFile/Servo- Serial Control/Servo- Serial Control.ino:4: undefined reference to `Servo::Servo()'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 2 second(s))
3 error(s), 0 warning(s) (0 minute(s), 2 second(s))
#include <Servo.h>

Thanks for Reply

I change #include "Servo.h" to #include <Servo.h> but had same Error,

when i hide #include <Servo.h>, CodeBlock ide will warning different "error: 'servo' was not declared in this scope"
so i think my case not a link problem.

:slight_smile:

Wing

Same code Compiling on Visual studio 2017 (with VS Arduino Pulgin), Also Work Fine! ...
( Visual studio need change <Servo.h> to "Servo.h")

I suspect that you have to ask this on a CodeBlocks forum.