-->
Page 1 of 2

Using fopen () fclose ()

PostPosted: Sat May 28, 2016 10:57 pm
by Collapsus
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

Re: Using fopen () fclose ()

PostPosted: Sat Jun 04, 2016 9:29 pm
by Mingy
Perhaps you might want to post your code.

Re: Using fopen () fclose ()

PostPosted: Sun Jun 05, 2016 5:16 pm
by Collapsus
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);
}

Re: Using fopen () fclose ()

PostPosted: Wed Jul 06, 2016 6:31 am
by hob
Any solution here?