I have been working and scouring the internet for the past couple of days trying to get my Eclipse project working with the Arduino libraries. I got my Eclipse environment set up using the playground/Code/Eclipse instructions and got the Blink program to run like many other people have. Now I'm trying to make a servo test program using the Servo library.
None of the posts I've found really cut straight to how to use the Arduino libraries in new projects. I've tried adding the Servo.cpp and Servo.h files to the project, adding the Servo library path to the AVR C++ Linker, and even tried creating a new static library for the Servo library. None of these things has worked. So I really have no clue what to do at this point.
Back to the point - how do I use the Arduino libraries with a new Eclipse project?
Set up your project and add main.cpp and other source files.
Then add the Servo library by linking the Servo.cpp file into your project:
(right click) -> New -> File -> Advanced -> Link to file in the file system -> Browse -> ".../libraries/Servo.cpp"
Or, you can import Servo.cpp into your project and keep a local, duplicate copy of Servo.cpp in your Eclipse workspace.
Now tell Eclipse where to find Servo.h:
(right click) - > Properties -> C/C++ Build -> Settings -> AVR C++ Compiler -> Directories -> add Include path ".../libraries/Servo"
You can also import Servo.h into your project and keep a local, duplicate copy, just as can for Servo.cpp. If you do this, then add an Include path to your project workspace instead of the arduino libraries folder.
I did like you said, linking the Servo.cpp and adding the directory for the Servo.h files. I'm getting an error on the build though.
./Servo.o: In function `Servo::read()':
Servo.cpp:(.text+0x238): undefined reference to `map(long, long, long, long, long)'
./Servo.o: In function `Servo::write(int)':
Servo.cpp:(.text+0x2fc): undefined reference to `map(long, long, long, long, long)'
I was getting this error before when I would include the Servo.cpp and Servo.h files in my project. Google searching the error hasn't really turned up anything useful.
Still get the undefined reference to map error and am using the compiled static library from Arduino Playground - Eclipse. In this case, mine is called libArduinoCore.a.
**** Build of configuration Release for project ServoTest ****
make all
Building file: ../main.cpp
Invoking: AVR C++ Compiler
avr-g++ -I/home/badger/arduino-0018/hardware/arduino/cores/arduino -I/home/badger/arduino-0018/libraries/Servo -Wall -Os -fpack-struct -fshort-enums -funsigned-char -funsigned-bitfields -fno-exceptions -mmcu=atmega168 -DF_CPU=16000000UL -MMD -MP -MF"main.d" -MT"main.d" -c -o"main.o" "../main.cpp"
./Servo.o: In function `Servo::read()':
Servo.cpp:(.text+0x238): undefined reference to `map(long, long, long, long, long)'
./Servo.o: In function `Servo::write(int)':
Servo.cpp:(.text+0x2fc): undefined reference to `map(long, long, long, long, long)'
Finished building: ../main.cpp
Building target: ServoTest.elf
Invoking: AVR C++ Linker
avr-gcc --cref -s -Os -o"ServoTest.elf" ./Servo.o ./main.o -lArduinoCore -lm -Wl,-Map,ServoTest.map,--cref -L/home/badger/workspace/ArduinoCore/Release -mmcu=atmega168
make: *** [ServoTest.elf] Error 1
Hmm... neither do I now that you mention it. I'm pretty new so I didn't realize I needed to compile Servo.cpp as well. Do I need to compile Servo.cpp and then add that to my project?
I'm sorry that I am not helping very much. I can't see the cause of the problem.
I noticed that my example, which does build, has a ATmega328P as a target, while yours is set for a different processor. Shouldn't matter, but ?
I also notice that the map() function it is complaining about is declared in WProgram.h. It looks like you have its directory in your Includes, so I don't know why it is not finding it.
Oh, you have been very helpful. I don't think I would have noticed Servo.cpp wasn't compiling. I think I'll try seeing if I can create a project with just Servo.cpp and see what happens.