Cannot find -lpololu collect2: ld returned 1 exit status

The command line returns:
localhost ~/orangutan/OrangutanLV168Demo $ avr-gcc -g -Wall -mcall-prologues -mmcu=atmega328p -Os test.o -W1,-gcc-sections -lpololu -o test.obj
/usr/local/lib/gcc/avr/4.6.3/…/…/…/…/avr/bin/ld: cannot find -lpololu
collect2: ld returned 1 exit status

Definitely I have path problem … just can not figure out how to fix it.
the directory looks like this:
localhost ~/orangutan/OrangutanLV168Demo $ ls -l total 88
-rw-r–r-- 1 nut wheel 14458 Mar 8 00:15 OrangutanLV168Demo.c
drwxr-xr-x 3 nut wheel 56 Jan 24 2013 default
drwxr-xr-x 20 nut wheel 4096 Feb 26 08:11 pololu
-rw-r–r-- 1 nut wheel 16992 Mar 8 00:23 test.o

When looking at directory: /usr/local/avr/include … it looks like this :
$ ls -l
total 156
-rw-r–r-- 1 root root 2601 Oct 5 05:37 alloca.h
-rw-r–r-- 1 root root 3642 Oct 5 05:37 assert.h
drwxr-xr-x 2 root root 4096 Oct 5 05:37 avr
drwxr-xr-x 2 root root 4096 Oct 5 05:37 compat
-rw-r–r-- 1 root root 5350 Oct 5 05:37 ctype.h
-rw-r–r-- 1 root root 2548 Oct 5 05:37 errno.h
-rw-r–r-- 1 root root 14877 Oct 5 05:37 inttypes.h
-rw-r–r-- 1 root root 15640 Oct 5 05:37 math.h
lrwxrwxrwx 1 root root 35 Feb 26 12:50 pololu -> /home/nut/orangutan/include/pololu
-rw-r–r-- 1 root root 4983 Oct 5 05:37 setjmp.h
-rw-r–r-- 1 root root 15906 Oct 5 05:37 stdint.h
-rw-r–r-- 1 root root 35444 Oct 5 05:37 stdio.h
-rw-r–r-- 1 root root 22564 Oct 5 05:37 stdlib.h
-rw-r–r-- 1 root root 5771 Oct 5 05:37 string.h
drwxr-xr-x 2 root root 4096 Oct 5 05:37 util

Is it a link problem that cannot be handled by avr linker ???
( it took me two days to find out how to post on the forum :laughing: )
Help please … Regards Kris

Hello, Kris.

What board are you trying to program? Is it an Orangutan LV-168 Robot Controller?

It sounds like you downloaded the “AVR Studio 4 test program for the Orangutan LV-168” from the Resources tab for that product and are trying to compile it. That demo is trying to use an older version of the Pololu AVR Library that provided a library file named “libpololu.a”. Modern versions of our library have different files for the different AVRs that are supported. For you, the correct file to use would be “libpololu_atmega168.a” and you should be able to find this file inside /usr/local/avr/lib. To fix the problem, you should try finding the “-lpololu” option in the Makefile and changing it to “-lpololu_atmega168”.

However, you might have a better experience if you instead follow the Pololu AVR Programming Quick Start Guide. Also, the AVR library download comes with many example programs that can be compiled for the Orangutan LV-168.


Little progress made with linker, the following command produces a.out file …
$ avr-ld -L /home/nut/orangutan/lib test.o

modification 1:
In Makefile need to change a line:


LIBS =-L /home/nut/orangutan/lib

The Make file returns error message ( before modification 1 was coming up with same error )
dep/OrangutanLV168Demo.o.d:1: *** multiple target patterns. Stop.

Can not point out where the problem is in Makefile … most likely do not “see woods in the forest” any longer… :frowning:

Fixed Makefile: The lines responsible were
OBJECTS = OrangutanLV168Demo.o
cc -c OrangutanLV168Demo.c

Further progress that brought a bit of success. I got to the stage where error occurs:

…/…/…/…/avr/lib/avr5/crtm168.o: In function __bad_interrupt': ../../../../crt1/gcrt1.S:195: undefined reference tomain’
collect2: ld returned 1 exit status
make: *** [OrangutanLV168Demo.elf] Error 1

Searching the net for reasons … nothing useful. By the way machine I am using for development is :
Linux localhost 3.10.7-gentoo #2 SMP PREEMPT Fri Mar 7 07:06:21 UTC 2014 x86_64 AMD FX™-8150 Eight-Core Processor AuthenticAMD GNU/Linux

Regards Kris

Hello, Kris.

It sounds like your current problem is that the GCC linker cannot find your definition of the “main” function. Does OrangutanLV168Demo.c still have its “int main()” function definition? There might be something wrong with the way you are compiling or linking. Could you clean out any intermediate files produced by compilation, then run “make” again, and post the full output from it?


Well … needed a brake to clear my brain from it, back to problem

Same output … with int main() or just main(). which is just almost at the end of program where the infinite loop is.

$ make
avr-gcc -mmcu=atmega168 -Wl,-gc-sections  -Wl,   /usr/local/avr/lib/pololu/libpololu_atmega168.a /usr/local/avr/lib/pololu/libpololu_atmega168.a -o OrangutanLV168Demo.elf
/usr/local/lib/gcc/avr/4.6.3/../../../../avr/lib/avr5/crtm168.o: In function `__bad_interrupt':
../../../../crt1/gcrt1.S:195: undefined reference to `main'
collect2: ld returned 1 exit status
make: *** [OrangutanLV168Demo.elf] Error 1

By the way target hardware is Orangutan sv-328 … right now just trying to get program build before is ready for burning in to target.

Thanks for your time … Kris

For some reason, the modified Makefile has decided to put the full path to the AVR library on the command line twice, but it has not put the path to any compiled file that might contain the definition of “main”. If there is such a file being produced, it would probably be called OrangutanLV168Demo.o and the Makefile would create it by compiling OrangutanLV168Demo.c.

The Orangutan LV-168 is different from the Orangutan SV-328. One of the main differences is that they use different AVR processors, so a program compiled for one cannot be easily run on the other. Instead of trying to compile a demo for the LV-168, I recommend that you use example code that was designed to work with the Orangutan SV-328. The Pololu AVR Library comes with many examples that were designed to work with the Orangutan SV-328 and you can get help building them from the Pololu AVR Programming Quick Start Guide.


As UNIX’s or Linux’s practically do not allow use of static libraries, at least discourage using them, for embedded systems where there is no OS (usually it is not necessary to have it) the build Makfiles need modification as in the code below;
It would be more practical to introduce variable PREFIX=/usr/local/avr/lib/pololu but for sake of clarity I am showing the full path … it is for my machine.
The Makfile for example program libpololu-avr/examples/atmega328p/lcd3-hello-world/test.c Command “make all” makes required .hex file correctly and “make program” burns it to Orangutan sv328 with Polololu’s programmer. And it works … finally. :smiley:

=============== Makefile =============================================

DEVICE = atmega328p
MCU = atmega328p
DEVICE ?= atmega168
MCU ?= atmega168

CFLAGS=-g -Wall -mcall-prologues -mmcu=$(MCU) $(DEVICE_SPECIFIC_CFLAGS) -Os

## Assuming that "pololu" library is there or it is a link
LDFLAGS=-Wl,-gc-sections -I. /usr/local/avr/lib/pololu/libpololu_atmega328p.a -L libpololu_$(DEVICE) -Wl,-relax

PORT = /dev/ttyACM0

all: $(TARGET).hex

	rm -f *.o *.hex *.obj *.hex

%.hex: %.obj
	$(OBJ2HEX) -R .eeprom -O ihex $< $@

test.o: test.c

%.obj: $(OBJECT_FILES)

program: $(TARGET).hex
	$(AVRDUDE) -p $(AVRDUDE_DEVICE) -c avrisp2 -P $(PORT) -U flash:w:$(TARGET).hex

=========================== end of Makefile ==========================
Thanks to all helping … reagrds Kris

I am glad you got it working, and thank you for telling us what you did. I wonder why the original Makefile did not work for you. If you run “avr-gcc --print-search-dirs” you should be able to see what directories GCC searches when it looks for libraries. If you make sure that libpololu_atmega328p.a is in one of the standard library directories, then the only linker flag you would need in order to link the library should be “-lpololu_atmega328p”.


Hi David
This is on my machine:

$ avr-gcc --print-search-dirs
install: /usr/local/lib/gcc/avr/4.6.3/
programs: =/usr/local/libexec/gcc/avr/4.6.3/:/usr/local/libexec/gcc/avr/4.6.3/:/usr/local/libexec/gcc/avr/:/usr/local/lib/gcc/avr/4.6.3/:/usr/local/lib/gcc/avr/:/usr/local/lib/gcc/avr/4.6.3/../../../../avr/bin/avr/4.6.3/:/usr/local/lib/gcc/avr/4.6.3/../../../../avr/bin/
libraries: =/usr/local/lib/gcc/avr/4.6.3/:/usr/local/lib/gcc/avr/4.6.3/../../../../avr/lib/avr/4.6.3/:/usr/local/lib/gcc/avr/4.6.3/../../../../avr/lib/

now when looking libraries:
$ ls /usr/local/avr/lib
avr25 crt86401.o crts4433.o crttn22.o crttn45.o libprintf_flt.a
avr3 crtc8534.o crts4434.o crttn2313.o crttn461.o libprintf_min.a
avr31 crts1200.o crts8515.o crttn24.o crttn84.o libscanf_flt.a
avr35 crts2313.o crts8535.o crttn25.o crttn85.o libscanf_min.a
avr4 crts2323.o crttn11.o crttn26.o crttn861.o pololu
avr5 crts2333.o crttn12.o crttn261.o ldscripts
avr51 crts2343.o crttn13.o crttn28.o libc.a
avr6 crts4414.o crttn15.o crttn44.o libm.a

$ ls -l /usr/local/avr/lib/pololu
lrwxrwxrwx 1 root root 24 Mar 9 04:29 /usr/local/avr/lib/pololu -> /home/nut/orangutan/lib
$ ls /home/nut/orangutan/lib
avr25 crts2343.o crttn25.o libpololu_atmega1284p_x2.a
avr3 crts4414.o crttn26.o libpololu_atmega168.a
avr31 crts4433.o crttn261.o libpololu_atmega324p.a
avr35 crts4434.o crttn28.o libpololu_atmega328p.a
avr4 crts8515.o crttn44.o libpololu_atmega48.a
avr5 crts8535.o crttn45.o libpololu_atmega644p.a
avr51 crttn11.o crttn461.o libprintf_flt.a
crt86401.o crttn12.o crttn84.o libprintf_min.a
crtc8534.o crttn13.o crttn85.o libscanf_flt.a
crts1200.o crttn15.o crttn861.o libscanf_min.a
crts2313.o crttn22.o libc.a
crts2323.o crttn2313.o libm.a
crts2333.o crttn24.o libpololu_atmega1284p.a

So I have copy of /usr/local/avr/lib in my working directory /home/nut/orangutan/lib
may be it is a bit “messy” … well so far works. I tried many example programs with success.
Now making Orangutan to drive two steppers … it will be telescope “go to” gadget.

Regards … Kris