I'm getting an "undefined reference to `__putchar'" error message, what does this mean?
This error indicates that you are using a stdio output function such as printf and that you haven't implemented the __putchar function that is required to actually carry out the output.
As an example, the following code demonstrates an implementation of __putchar that outputs to a UART:
void
__putchar(int ch)
{
if (ch == '\n')
UARTWriteChar('\r');
UARTWriteChar(ch);
}
Note: If all want to do is make the stdio functions output to the debug terminal rather than hardware you should set the Library Options > I/O Library Name project property to debug or, alternatively, use the debug I/O functions directly (for example use debug_printf rather than printf).
Comments
2 comments
I tried changing the I/O Library Name to debug in my project's Debug properties, but I still get the same error. Is there some other setting that need to be changed or a definition that needs to be set?
Do you have "Enable Unused Symbol Removal" set to be "No" - if so then the C library will require __putchar to be defined even if it isn't used. We'll fix/workaround this in the next release.
Please sign in to leave a comment.