News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

WinAVR stdio functions problem

Started by Longin, February 01, 2014, 01:35:26 PM

Previous topic - Next topic

Longin

Hello
This is my first post and I would like to say that I have read forum rules...so I hope u won´t beat me for this.

Windows XP SP3, last WinAVR (20100110) and fresh installation of Code::blocks (default settings, detected toolchains etc)
Everything have worked fine until now
I have problem with using function sprintf() from stdio.h.
Example code:

#include <avr/io.h>
#include <stdio.h>
int main(void) {
    char buffer[10];
    unsigned int temp;
    sprintf( buffer, "%d", temp) ;
    while(1) ;
    return 0;
}
}


Build log:

-------------- Build: Debug in Pokus (compiler: GNU GCC Compiler for AVR)---------------

avr-gcc.exe -Wall -mmcu=atmega16 -DF_CPU=16000000UL -g -IC:\WinAVR\avr\include -c main.c -o obj\Debug\main.o
avr-g++.exe -LC:\WinAVR\avr\lib -o bin\Debug\Pokus.elf obj\Debug\main.o  -mmcu=atmega16 -Wl,-Map=bin\Debug\Pokus.map,--cref 
C:\WinAVR\avr\lib\libc.a(vfprintf_std.o): In function `vfprintf':
(.text.avr-libc+0xd4): undefined reference to `__mulhi3'
C:\WinAVR\avr\lib\libc.a(vfprintf_std.o): In function `vfprintf':
(.text.avr-libc+0xe4): undefined reference to `__mulhi3'


consulting C::B FAQ and Google I changed Linker options in Project build options to:
-Wl
-u,vfprintf
-lprintf_flt
-lm


from default:
-mmcu=atmega16
-Wl,-Map=$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).map,--cref


and it "fixed" the problem.
Build log:
avr-gcc.exe -mmcu=atmega16 -Wall -DF_CPU=16000000UL -g -IC:\WinAVR\avr\include -c main.c -o obj\Debug\main.o
avr-g++.exe -LC:\WinAVR\avr\lib -o bin\Debug\Pokus.elf obj\Debug\main.o  -Wl -u,vfprintf -lprintf_flt -lm 
Output file is bin\Debug\Pokus.elf with size 5.09 KB
Running project post-build steps
cmd /c "avr-objdump -h -S bin\Debug\Pokus.elf > bin\Debug\Pokus.lss"
avr-objcopy -R .eeprom -R .fuse -R .lock -R .signature -O ihex bin\Debug\Pokus.elf bin\Debug\Pokus.hex
avr-objcopy --no-change-warnings -j .eeprom --change-section-lma .eeprom=0 -O ihex bin\Debug\Pokus.elf bin\Debug\Pokus.eep


.hex is created and program in mcu works. It´s fine but it mess Project linker settings in C::B doesn´t it?
I always can use C::B Tool for own Makefile what works too and I have complete view over compilation/linking process but using IDE is using IDE.

Sorry for my creepy English