Search code examples
eclipseavravr-gccavrdude

Error while using custom library "undefined reference" [AVR]


I am using Eclipse in order to program a PID line follower robot. The microcontroller used is an Atmega328P. For that, I am using one QTR-8RC IR sensor, by Pololu and two modified servos for continuous rotation. I and my partner decided to use the Pololu AVR library since it contains functions specifically for servo control and for the IR sensor.

The problem is Eclipse does recognize the library but it does not compile.

Eg:

#include <pololu/orangutan.h>
#include <pololu/3pi.h>
#include <pololu/qtr.h>
#include <pololu/encoders.h>

unsigned char qtr_rc_pins[]={IO_D2,IO_D3,IO_D4,IO_D5,IO_D6,IO_D7}; //Setup Qtr pins
  void main(){
       qtr_rc_init(qtr_rc_pins,6,2000,255); //starts qtr
       while(1){} //does nothing

Whenever I try to compile this eclipse gives me the following error:

undefined reference to `qtr_rc_init'

More information on the Pololu AVR library.


Solution

  • The undefined reference error you are getting can be solved by adding -lpololu_atmega328p to your linker flags. For more information about what compiler and linker options you need, see the "Using the Pololu AVR Library for your own projects" section in the user's guide you linked to.