Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't compile a program containing a 'printf' or 'snprintf' call #357

Open
ilyad opened this issue Jan 29, 2019 · 4 comments
Open

can't compile a program containing a 'printf' or 'snprintf' call #357

ilyad opened this issue Jan 29, 2019 · 4 comments

Comments

@ilyad
Copy link

ilyad commented Jan 29, 2019

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

@igagis
Copy link

igagis commented Jan 29, 2019

I'm seeing same issue

@igagis
Copy link

igagis commented Jan 30, 2019

It turned out one has to use os_printf() instead of printf()

@igagis
Copy link

igagis commented Feb 4, 2019

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.

@igagis
Copy link

igagis commented May 9, 2019

@ilyad close the issue, as it is solved now...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants