I'm trying for the first time to use Arduino Libraries (Servo.h & Servo.cpp in this case) in Eclipse IDE.

So far I've managed to compile and run Arduino code using this tutorial (I suppose many of you already know it).

The problem comes when I add the Servo.cpp and Servo.h files and try to run the program:

    13:35:08 **** Incremental Build of configuration Release for project Servo ****
make all 
arduinoEclipse/subdir.mk:268: warning: overriding commands for target `arduinoEclipse/wiring_pulse.o'
arduinoEclipse/subdir.mk:261: warning: ignoring old commands for target `arduinoEclipse/wiring_pulse.o'
Building file: ../ServoTest.cpp
Invoking: AVR C++ Compiler
avr-g++ -I"C:\arduino\arduinoEclipse" -Wall -Os -fpack-struct -fshort-enums -ffunction-sections -fdata-sections -funsigned-char -funsigned-bitfields -fno-exceptions -mmcu=atmega328p -DF_CPU=1600000UL -MMD -MP -MF"ServoTest.d" -MT"ServoTest.o" -c -o "ServoTest.o" "../ServoTest.cpp"
Finished building: ../ServoTest.cpp

Building target: Servo.elf
Invoking: AVR C++ Linker
avr-g++ -Wl,-Map,Servo.map,--cref -mrelax -Wl,--gc-sections -mmcu=atmega328p -o "Servo.elf"  ./arduinoEclipse/CDC.o ./arduinoEclipse/HardwareSerial.o ./arduinoEclipse/HardwareSerial0.o ./arduinoEclipse/HardwareSerial1.o ./arduinoEclipse/HardwareSerial2.o ./arduinoEclipse/HardwareSerial3.o ./arduinoEclipse/IPAddress.o ./arduinoEclipse/PluggableUSB.o ./arduinoEclipse/Print.o ./arduinoEclipse/Servo.o ./arduinoEclipse/Stream.o ./arduinoEclipse/Tone.o ./arduinoEclipse/USBCore.o ./arduinoEclipse/WInterrupts.o ./arduinoEclipse/WMath.o ./arduinoEclipse/WString.o ./arduinoEclipse/abi.o ./arduinoEclipse/hooks.o ./arduinoEclipse/main.o ./arduinoEclipse/new.o ./arduinoEclipse/wiring.o ./arduinoEclipse/wiring_analog.o ./arduinoEclipse/wiring_digital.o ./arduinoEclipse/wiring_pulse.o ./arduinoEclipse/wiring_shift.o  ./ServoTest.o   
./ServoTest.o: In function `setup':
ServoTest.cpp:(.text.setup+0x8): undefined reference to `Servo::attach(int)'
./ServoTest.o: In function `loop':
ServoTest.cpp:(.text.loop+0x20): undefined reference to `Servo::writeMicroseconds(int)'
ServoTest.cpp:(.text.loop+0x5a): undefined reference to `Servo::writeMicroseconds(int)'
ServoTest.cpp:(.text.loop+0xbc): undefined reference to `Servo::write(int)'
./ServoTest.o: In function `_GLOBAL__sub_I_myservo':
ServoTest.cpp:(.text.startup._GLOBAL__sub_I_myservo+0x4): undefined reference to `Servo::Servo()'
collect2.exe: error: ld returned 1 exit status
make: *** [Servo.elf] Error 1

As you can see in the console output, it compiles correctly, but when it comes to the linker, it doesn't find the function references from the Servo.cpp.

As I have seen in this post, the problem comes from the fact that I need also to generate an .a (static library) file in order to link both .h and .cpp files. Still, I have no idea how I am supposed to generate this file.

For this project, I have just added in arduinoEclipse folder all the .cpp and .h files from C:\arduino\hardware\arduino\avr\cores\arduino, C:\arduino\hardware\arduino\avr\variants\standard & C:\arduino\libraries\Servo.

Do you see what I could be missing?

Thank you in advance

  • The article explains 2 roads. You should at least tell which one you took.
    – jantje
    May 20, 2017 at 20:37
  • I'm using AVR Plugin
    – Alvaro
    May 20, 2017 at 22:24

2 Answers 2


The arduino build process is described here: https://www.arduino.cc/en/Hacking/BuildProcess
You do not really need to build a archive. You can link all your source files but that will result in a far bigger file to upload to the embedded device.
The normal CDT process to build a archive is by having 2 projects. One for the "archive" one for your sketch and then use project dependencies.
However since Arduino IDE 1.5 this process is hard to maintain because changing settings for your sketch may force you to change your archive compilation settings.
As far as I know; out of the box CDT does not support creating a library and linking it to a "executable" in one project. This is something Sloeber (road 1 in the article) has added.
I know this because I'm authoring Sloeber.


I don't have eclipse handy right now, so I may not have the menu options verbatim here, but with eclipse there are more steps to including a library than just writing the line in the code. Go to the project in the project explorer and right click the project name. Hit import and select the option for importing Arduino libraries into the sketch. It should bring up a dialog with a list of all the libraries you have installed and you can choose from there. Then there will be a folder in your project called includes IIRC and it will have a link to the library that you imported. Now when you compile it will find the library.

  • There is no "import arduino libraries" if you followed road 2 in the article. This is so because "import arduino libraries" is part of Sloeber. Note that the latest versions of sloeber just adding the include is sufficient in many cases. Also note that there is a menu item Arduino which contains "import arduino libraries"
    – jantje
    May 21, 2017 at 10:47
  • Thanks for the correction. I just assumed that the poster was using the Arduino plugin for Eclipse.
    – Delta_G
    May 21, 2017 at 15:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.