Article ID: 000085005 Content Type: Troubleshooting Last Reviewed: 10/16/2012

Why do I get the error "undefined reference to 'getc'" when attempting to use alt_getchar() with Nios II?

Environment

BUILT IN - ARTICLE INTRO SECOND COMPONENT
Description

This issue can be seen when both the "Enable Small C library" option is checked and the "Enable Lightweight Device Driver API" option is unchecked. 

The "Enable Small C library" option has the effect of removing a number of functions from the Nios II Board Support Package (BSP), including the STDIN routines.  These functions includes the routine getchar(), which calls getc().

The "Enable Lightweight Device Driver API" optimizes the functions alt_getchar(), alt_putstr(), alt_printf(), and alt_putchar().  Without this option checked, these functions directly call their C library equivalents of getchar(), putstr(), printf() and putchar().

Hence with "Enable Small C library" checked, and "Enable Lightweight Device Driver API" unchecked, alt_getchar() is mapped to the getchar() function, which is no longer in the library.

In order to successfully use the alt_getchar function, the user needs to either uncheck "Enable Small C library" or enable, "Enable Lightweight Device Driver API" in the BSP settings.

Resolution

This issue can be seen when both the "Enable Small C library" option is checked and the "Enable Lightweight Device Driver API" option is unchecked. 

The "Enable Small C library" option has the effect of removing a number of functions from the Nios II Board Support Package (BSP), including the STDIN routines.  These functions includes the routine getchar(), which calls getc().

The "Enable Lightweight Device Driver API" optimizes the functions alt_getchar(), alt_putstr(), alt_printf(), and alt_putchar().  Without this option checked, these functions directly call their C library equivalents of getchar(), putstr(), printf() and putchar().

Hence with "Enable Small C library" checked, and "Enable Lightweight Device Driver API" unchecked, alt_getchar() is mapped to the getchar() function, which is no longer in the library.

In order to successfully use the alt_getchar function, the user needs to either uncheck "Enable Small C library" or enable, "Enable Lightweight Device Driver API" in the BSP settings.

Related Products

This article applies to 1 products

Intel® Programmable Devices