can't compile a program containing a 'printf' or 'snprintf' call
ilyad opened this issue · 4 comments
Trying to compile a simple function containing printf("in '%s': x=%d, y=%f\n", __FILE__, x, y);
I'm getting linker errors (see below). With "snprintf" there are less errors, but nevertheless it doesn't link.
Here is the command line (the main.o file contains just a minimal example, compiling and working correctly, without any printf calls):
xtensa-lx106-elf-g++ -c -MF "print.d" -MD -MP -o "print.o" print.c
xtensa-lx106-elf-g++ -Teagle.app.v6.ld main.o print.o -nostdlib -Wl,--start-group -lmain -lnet80211 -lwpa -llwip -lpp -lphy -lc -Wl,--end-group -lgcc -o "maincpu"
and the linker errors:
/ld: maincpu section '.text' will not fit in region 'iram1_0_seg'
/ld: region 'iram1_0_seg' overflowed by 9068 bytes
/libc.a(lib_a-wsetup.o):(.literal+0x0): undefined reference to '_free_r'
/libc.a(lib_a-wsetup.o): In function '__swsetup_r':
/libc/stdio/wsetup.c:57: undefined reference to '_free_r'
/libc.a(lib_a-fflush.o): In function '__sflush_r':
/libc/stdio/fflush.c:162: undefined reference to '_free_r'
/libc.a(lib_a-findfp.o):(.literal+0x4): undefined reference to '_malloc_r'
/libc.a(lib_a-findfp.o): In function '__sfmoreglue':
/libc/stdio/findfp.c:88: undefined reference to '_malloc_r'
/libc.a(lib_a-makebuf.o):(.literal+0x8): undefined reference to '_fstat_r'
/libc.a(lib_a-makebuf.o): In function '__smakebuf_r':
/libc/stdio/makebuf.c:59: undefined reference to '_fstat_r'
/libc/stdio/makebuf.c:95: undefined reference to '_malloc_r'
/libc.a(lib_a-stdio.o):(.literal+0x4): undefined reference to '_read_r'
/libc.a(lib_a-stdio.o):(.literal+0x8): undefined reference to '_lseek_r'
/libc.a(lib_a-stdio.o):(.literal+0xc): undefined reference to '_write_r'
/libc.a(lib_a-stdio.o):(.literal+0x10): undefined reference to '_close_r'
/libc.a(lib_a-stdio.o): In function '__sread':
/libc/stdio/stdio.c:48: undefined reference to '_read_r'
/libc.a(lib_a-stdio.o): In function '__swrite':
/libc/stdio/stdio.c:89: undefined reference to '_lseek_r'
/libc/stdio/stdio.c:97: undefined reference to '_write_r'
/libc.a(lib_a-stdio.o): In function '__sseek':
/libc/stdio/stdio.c:117: undefined reference to '_lseek_r'
/libc.a(lib_a-stdio.o): In function '__sclose':
/libc/stdio/stdio.c:135: undefined reference to '_close_r'
/libc.a(isatty.o): In function '_isatty_r':
/libc/sys/xtensa/isatty.c:13: undefined reference to '_fstat_r'
/libc.a(lib_a-fclose.o): In function '_fclose_r':
/libc/stdio/fclose.c:102: undefined reference to '_free_r'
/libc/stdio/fclose.c:104: undefined reference to '_free_r'
/libc/stdio/fclose.c:106: undefined reference to '_free_r'
/libc.a(lib_a-fvwrite.o):(.literal+0x0): undefined reference to '_realloc_r'
/libc.a(lib_a-fvwrite.o): In function '__sfvwrite_r':
/libc/stdio/fvwrite.c:143: undefined reference to '_malloc_r'
/libc/stdio/fvwrite.c:154: undefined reference to '_realloc_r'
/libc/stdio/fvwrite.c:160: undefined reference to '_free_r'
collect2: error: ld returned 1 exit status
I'm seeing same issue
It turned out one has to use os_printf()
instead of printf()
Also, need to define the ICACHE_FLASH
macro, i.e. pass -D ICACHE_FLASH
to the compiler. This will make functions marked as ICACHE_FLASH_ATTR
to not be placed to iram
. Then iram
will not be consumed without need.