Discuss here different C compiler set ups, and compiling executables for the ESP8266

User avatar
By Collapsus
#48181 I need to use the functions of file I/O, fclose fopen () write and read to files in esp8266 sdk firmware, but when compiling my program it presents the error:

/../../..//sdk/lib/libcirom.a(lib_a-fclose.o):(.irom0.literal+0x0): undefined reference to `_free_r'
../../../..//sdk/lib/libcirom.a(lib_a-fclose.o): In function `_fclose_r':
/home/wjg/Repo/esp-open-sdk/crosstool-NG/.build/src/newlib-2.0.0/newlib/libc/stdio/fclose.c:102: undefined reference to `_free_r'
/home/wjg/Repo/esp-open-sdk/crosstool-NG/.build/src/newlib-2.0.0/newlib/libc/stdio/fclose.c:104: undefined reference to `_free_r'
/home/wjg/Repo/esp-open-sdk/crosstool-NG/.build/src/newlib-2.0.0/newlib/libc/stdio/fclose.c:106: undefined reference to `_free_r'
../../../..//sdk/lib/libcirom.a(lib_a-fflush.o): In function `__sflush_r':
/home/wjg/Repo/esp-open-sdk/crosstool-NG/.build/src/newlib-2.0.0/newlib/libc/stdio/fflush.c:162: undefined reference to `_free_r'
../../../..//sdk/lib/libcirom.a(lib_a-findfp.o):(.irom0.literal+0x4): undefined reference to `_malloc_r'
../../../..//sdk/lib/libcirom.a(lib_a-findfp.o): In function `__sfmoreglue':
/home/wjg/Repo/esp-open-sdk/crosstool-NG/.build/src/newlib-2.0.0/newlib/libc/stdio/findfp.c:88: undefined reference to `_malloc_r'
../../../..//sdk/lib/libcirom.a(lib_a-fopen.o):(.irom0.literal+0x0): undefined reference to `_open_r'
../../../..//sdk/lib/libcirom.a(lib_a-fopen.o): In function `_fopen_r':
/home/wjg/Repo/esp-open-sdk/crosstool-NG/.build/src/newlib-2.0.0/newlib/libc/stdio/fopen.c:141: undefined reference to `_open_r'
../../../..//sdk/lib/libcirom.a(lib_a-fseeko.o):(.irom0.literal+0xc): undefined reference to `_fstat_r'
../../../..//sdk/lib/libcirom.a(lib_a-fseeko.o): In function `_fseeko_r':
/home/wjg/Repo/esp-open-sdk/crosstool-NG/.build/src/newlib-2.0.0/newlib/libc/stdio/fseeko.c:231: undefined reference to `_fstat_r'
/home/wjg/Repo/esp-open-sdk/crosstool-NG/.build/src/newlib-2.0.0/newlib/libc/stdio/fseeko.c:258: undefined reference to `_fstat_r'
/home/wjg/Repo/esp-open-sdk/crosstool-NG/.build/src/newlib-2.0.0/newlib/libc/stdio/fseeko.c:313: undefined reference to `_free_r'
/home/wjg/Repo/esp-open-sdk/crosstool-NG/.build/src/newlib-2.0.0/newlib/libc/stdio/fseeko.c:335: undefined reference to `_free_r'
/home/wjg/Repo/esp-open-sdk/crosstool-NG/.build/src/newlib-2.0.0/newlib/libc/stdio/fseeko.c:362: undefined reference to `_free_r'
../../../..//sdk/lib/libcirom.a(lib_a-makebuf.o): In function `__smakebuf_r':
/home/wjg/Repo/esp-open-sdk/crosstool-NG/.build/src/newlib-2.0.0/newlib/libc/stdio/makebuf.c:59: undefined reference to `_fstat_r'
/home/wjg/Repo/esp-open-sdk/crosstool-NG/.build/src/newlib-2.0.0/newlib/libc/stdio/makebuf.c:95: undefined reference to `_malloc_r'
../../../..//sdk/lib/libcirom.a(lib_a-refill.o): In function `__srefill_r':
/home/wjg/Repo/esp-open-sdk/crosstool-NG/.build/src/newlib-2.0.0/newlib/libc/stdio/refill.c:88: undefined reference to `_free_r'
../../../..//sdk/lib/libcirom.a(lib_a-stdio.o):(.irom0.literal+0x4): undefined reference to `_read_r'
../../../..//sdk/lib/libcirom.a(lib_a-stdio.o):(.irom0.literal+0x8): undefined reference to `_lseek_r'
../../../..//sdk/lib/libcirom.a(lib_a-stdio.o):(.irom0.literal+0xc): undefined reference to `_write_r'
../../../..//sdk/lib/libcirom.a(lib_a-stdio.o):(.irom0.literal+0x10): undefined reference to `_close_r'
../../../..//sdk/lib/libcirom.a(lib_a-stdio.o): In function `__sread':
/home/wjg/Repo/esp-open-sdk/crosstool-NG/.build/src/newlib-2.0.0/newlib/libc/stdio/stdio.c:48: undefined reference to `_read_r'
../../../..//sdk/lib/libcirom.a(lib_a-stdio.o): In function `__swrite':
/home/wjg/Repo/esp-open-sdk/crosstool-NG/.build/src/newlib-2.0.0/newlib/libc/stdio/stdio.c:89: undefined reference to `_lseek_r'
/home/wjg/Repo/esp-open-sdk/crosstool-NG/.build/src/newlib-2.0.0/newlib/libc/stdio/stdio.c:97: undefined reference to `_write_r'
../../../..//sdk/lib/libcirom.a(lib_a-stdio.o): In function `__sseek':
/home/wjg/Repo/esp-open-sdk/crosstool-NG/.build/src/newlib-2.0.0/newlib/libc/stdio/stdio.c:117: undefined reference to `_lseek_r'
../../../..//sdk/lib/libcirom.a(lib_a-stdio.o): In function `__sclose':
/home/wjg/Repo/esp-open-sdk/crosstool-NG/.build/src/newlib-2.0.0/newlib/libc/stdio/stdio.c:135: undefined reference to `_close_r'
../../../..//sdk/lib/libcirom.a(isatty.o): In function `_isatty_r':
/home/wjg/Repo/esp-open-sdk/crosstool-NG/.build/src/newlib-2.0.0/newlib/libc/sys/xtensa/isatty.c:13: undefined reference to `_fstat_r'
collect2: error: ld returned 1 exit status
../../../..//scripts/Makefile:154: recipe for target 'build/app.out' failed

Thanks
User avatar
By Collapsus
#48641 Code:

#include "osapi.h"
#include "user_interface.h"
#include "uart.h"
#include "stdlib.h"
#include "string.h"
#include "stdarg.h"
#include "stddef.h"
#include "stdio.h"
#include "user_interface.h"


//user_init is the user entry point of the Espressif SDK
void ICACHE_FLASH_ATTR user_init(void)
{
// Set baudrate
uart_init(BIT_RATE_115200, BIT_RATE_115200);
os_delay_us(100);

FILE *fd = 0;
fd = fopen("config", "wb");
char x[10]="ABCDEFGHIJ";
fwrite(x, sizeof(x[0]), sizeof(x)/sizeof(x[0]), fd);
fclose(fd);
}