I designed a static library for use in my AVR projects, but I'm having trouble linking it to an application. It reports this error:
libteleobjects/libteleobjects.a(telesignals.c.obj): In function `telesignal_get_event_data':
/home/claudio/git/ucp-usc64/libteleobjects/telesignals.c:559: undefined reference to `__mulhi3'
/home/claudio/git/ucp-usc64/libteleobjects/telesignals.c:561: undefined reference to `__mulhi3'
/home/claudio/git/ucp-usc64/libteleobjects/telesignals.c:561: undefined reference to `__mulhi3'
/home/claudio/git/ucp-usc64/libteleobjects/telesignals.c:561: undefined reference to `__mulhi3'
I found an interesting investigation to the same problem here, but since his solution is all about ADA I have no idea how to fix it in my case, which is a C
application. It gave me nice tips though, like using avr-nm
to search for this symbol in the system libraries. Unlike in his case, here the symbol __mulhi3
displays as U
(undefined) even in the avr system libs where it was supposed to be found (libgcc.a
for his libs from AVR-GCC 4.7.2 - mine is 4.8.0), so I guess the __mulhi3
is not defined at all(!?). I would expect it should appear as T
(defined in the text
section) in the system libs (.a
files in /usr/avr/lib and subdirs). Any tips? As a sidenote, I'm using CMake as the build system.
EDIT:
Like suggested here and in the answer below, adding the math library to the end of linking would supposedly solve the problem, but CMake is already doing it and it didn't work yet:
Linking C executable ucp-usc64.elf
/usr/bin/cmake -E cmake_link_script CMakeFiles/ucp-usc64.dir/link.txt --verbose=1
/usr/bin/avr-gcc -g -Os -mcall-prologues -ffunction-sections -fdata-sections -Os -DNDEBUG -w -mcall-prologues -ffunction-sections -fdata-sections -Wl,--gc-sections -lm -Wl,--gc-sections -lm -mmcu=atmega644p CMakeFiles/ucp-usc64.dir/main.c.obj CMakeFiles/ucp-usc64.dir/modutr_callbacks.c.obj -o ucp-usc64.elf -lc -lm avr-drivers/libavr_drivers.a modutr-slave/lib/libmodutr_slave.a libteleobjects/libteleobjects.a -lc -lm
libteleobjects/libteleobjects.a(telesignals.c.obj): In function `telesignal_get_event_data':
/home/claudio/git/ucp-usc64/libteleobjects/telesignals.c:559: undefined reference to `__mulhi3'
/home/claudio/git/ucp-usc64/libteleobjects/telesignals.c:561: undefined reference to `__mulhi3'
/home/claudio/git/ucp-usc64/libteleobjects/telesignals.c:561: undefined reference to `__mulhi3'
/home/claudio/git/ucp-usc64/libteleobjects/telesignals.c:561: undefined reference to `__mulhi3'
collect2: error: ld returned 1 exit status