Undefined reference to f_gets/f_puts error

olegboicenco
Posts: 10
Joined: Sun Jul 26, 2020 2:48 pm

Undefined reference to f_gets/f_puts error

Postby olegboicenco » Mon Aug 31, 2020 11:19 am

Hi to All!
I have an ESP-IDF project contained f_open(..) and f_puts(..)/f_gets(..).
Here is the part of my code:

if(f_open(&fil, u8GlobalNameOfFileName, FA_READ) == FR_OK)
{
f_gets(fileText, sizeof(FirstTextInCsv), &fil);
if(strcmp(fileText,FirstTextInCsv) == false)
{
PRINTF("The flash was populated\n");
ret = true;
}
}
else
{
PRINTF("Failed to open file for reading\n");
}
f_close(&fil);


After the compilation step, I get a linker errors:

c:/.espressif/tools/xtensa-esp32-elf/esp-2020r2-8.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(sd_card.c.obj):(.literal.SDHC_CheckFirstWrite+0x8): undefined reference to `f_gets'

c:/.espressif/tools/xtensa-esp32-elf/esp-2020r2-8.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(sd_card.c.obj):(.literal.SDHC_WriteFirstRowInCsv+0x0): undefined reference to `f_puts'

It is very strange that there are no errors for f_open (..) or f_close(..)!

I noticed that the functions f_open(), f_puts(), f_gets() are declared in the file {ESP-IDF}\components\fatfs\src\ff.h. And there are no “ifdefs” “separating” them. I also noticed that in the same directory there is a file ffconf.h, in which "FF_USE_STRFUNC 0" is defined with the following comments:

/* This option switches string functions, f_gets(), f_putc(), f_puts() and f_printf().
/
/ 0: Disable string functions.
/ 1: Enable without LF-CRLF conversion.
/ 2: Enable with LF-CRLF conversion. */


It is logical to assume that FF_USE_STRFUNC must be defined as 1 or 2 to be able to use f_puts() and f_gets(). But is it right for the user to make changes to the framework file?
Can you please tell me how to solve or "work around" this problem?

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: Undefined reference to f_gets/f_puts error

Postby ESP_igrr » Tue Sep 01, 2020 12:24 am

Hi olegboicenco,
Indeed we hadn't enabled FF_USE_STRFUNC option, as we assume that FATFS library will be used together with the VFS mechanism. That way you can use C standard library functions (fgets, fputs) to work with files.
If you have some existing code which uses FATFS APIs, you may enable FF_USE_STRFUNC. I don't think it will cause any side effects.

olegboicenco
Posts: 10
Joined: Sun Jul 26, 2020 2:48 pm

Re: Undefined reference to f_gets/f_puts error

Postby olegboicenco » Fri Oct 23, 2020 1:33 pm

Now it's clear! Thank you, ESP_Igrr!!

tyethgundry
Posts: 9
Joined: Sat Nov 07, 2020 10:02 pm

Re: Undefined reference to f_gets/f_puts error

Postby tyethgundry » Sun Dec 13, 2020 10:53 pm

Thanks from a troubled Keil + nordic semiconductor nrf52840-dk / nrf5 sdk user, and esp32 customer :D

Who is online

Users browsing this forum: No registered users and 174 guests