I am using Code::Blocks with AVR-GCC toolchain from Microchip (Atmel). I am trying to compile program for Atmega32
. I get "Undefined reference to __mulhi3
" when I try to compile program that uses sprintf()
function. Without this function I get no error. The same program compiled in Atmel Studio or in Code::Blocks under Linux works fine.
#include <avr/io.h>
#include <stdio.h>
int main(void)
{
char buf[20];
sprintf(buf, "Hello %d", 1);
while(1);
return 0;
}
Problem is caused by default settings of Code::Blocks for GNU GCC Compiler for AVR
- there are unnecessary include paths to C:/WinAVR/avr/lib
. You should go to
Settings → Compiler... → GNU GCC Compiler for AVR → Search directiories → Linker
and clear list of include paths. If the list is not empty, linker tries to link against wrong version of library.