Topic : sprintf error

Forum : ST7/STM8

Original Post
Post Information Post
October 1, 2011 - 7:12am
Guest

please helpl me find the mistake:
I use ST visual develop + raisonance.
simple code:
#include

void main(){
char str[20];

sprintf (str,"test %d",123);
while (1);
}

If i compile it's ok, but when I build the poject it gives out error
***ERROR 100 : UNRESOLVED EXTERNAL
SYMBOL : ?putchar(WRITECHAR)

LINK/LOCATE RUN COMPLETE, 1 ERROR FOUND.
The command: "rlstm8 -P "Debug\main.o" TO(Debug\counter.aof) LIBPATH("C:\Program Files\Raisonance\Ride\Lib\ST7") DEBUGLINES DEBUGPUBLICS DEBUGSYMBOLS PR(Debug\counter.map) DATASTART(0x0) RAMSIZE(0x800) CODESTART(0x8000) CODESIZE(0x8000) STACKTOP(0x800) STACKSIZE(0x201) EEPROMSTART(0x1000) EEPROMSIZE(0x400) " has failed, the returned value is: 1
exit code=1.

what's wrong?

Replies
Post Information Post
+1
0
-1
October 3, 2011 - 10:02am
Raisonance Support Team

Hi,

Thanks for your report.
This is a known limitation : The sprintf() function requires that the putchar() function is present in your project. Failing to have it will result in a
linker error 100 : UNRESOLVED EXTERNAL.

This is because the C library is optimized for the overall size of applications, so printf and sprintf have been written as a single piece of code which either copies the emitted characters to a memory buffer (case of sprintf) or emits the characters through putchar (case of printf).

A workaround to this limitation is to add a "dummy" call to putchar in a harmless place in your code.
A good place for placing this dummy "putchar(0)" call is at the bottom of your main() code.

Let us know if you still have some issues on this.
Best Regards,

+1
0
-1
October 3, 2011 - 6:59pm
Guest

Thanks Bruno.
I've tried your solution :

#include 

char str[20];

void main(void)
{

   sprintf(str,"test %d",123);
   putchar(0);
}

But it still causes error:
***ERROR 100 : UNRESOLVED EXTERNAL
      SYMBOL : ?putchar(WRITECHAR)

***ERROR 100 : UNRESOLVED EXTERNAL
      SYMBOL : ?putchar(MAIN)

LINK/LOCATE RUN COMPLETE, 2 ERRORS FOUND.
 The command: "rlstm8 -P "Debug\main.o" TO(Debug\test.aof) LIBPATH("C:\Program Files\Raisonance\Ride\Lib\ST7")  DEBUGLINES DEBUGPUBLICS DEBUGSYMBOLS PR(Debug\test.map)  DATASTART(0x0) RAMSIZE(0x800) CODESTART(0x8000) CODESIZE(0x8000) STACKTOP(0x800) STACKSIZE(0x201) EEPROMSTART(0x1000) EEPROMSIZE(0x400) " has failed, the returned value is: 1
exit code=1.

test.elf - 3 error(s), 0 warning(s)

+1
0
-1
October 4, 2011 - 9:35am
Raisonance Support Team

Hi,

I guess you are not using the Ride7 integrated environment. It would have been taking care of the UART type necessary to your specific microcontroller.
What you must do is add a SCINAME linker directive, for example:
SCINAME(STM8)

This should make it.
BR

+1
0
-1
October 4, 2011 - 10:46am
Guest

Hi, Bruno.
Thanks for your help.
As I said before I use visual develope IDE
I just added SCINAME(STM8) to linker options and it works.
thanks alot.