Issue
I have a header file that declares two functions:
// ff.h
FRESULT f_mount (FATFS* fs, const TCHAR* path, BYTE opt);
FRESULT f_mkfs (const TCHAR* path, const MKFS_PARM* opt, void* work, UINT len);
And a source file that defines both functions:
// ff.c
#include "ff.h"
FRESULT f_mount (FATFS* fs, const TCHAR* path, BYTE opt) {...}
FRESULT f_mkfs (const TCHAR* path, const MKFS_PARM* opt, void* work, UINT len) {...}
When I call them from my main file, however, one of the functions works perfectly and the other raises undefined reference
, even though they are in the same file:
#include "ff.h"
[...]
fresult = f_mount(&fs, "0:", 1);
[...]
fresult = f_mkfs("0:", &fmt_opt, work, sizeof work);
>> output:
11:24:45 **** Incremental Build of configuration Debug for project laser_manual ****
make -j8 all
arm-none-eabi-gcc -o "laser_manual.elf" @"objects.list" -mcpu=cortex-m4 -T"C:\Users\Pesquisa2\Documents\stm32\LM_STM32\STM32F407ZGTX_FLASH.ld" --specs=nosys.specs -Wl,-Map="laser_manual.map" -Wl,--gc-sections -static --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -u _printf_float -u _scanf_float -Wl,--start-group -lc -lm -Wl,--end-group
c:\st\stm32cubeide_1.9.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.win32_1.0.0.202111181127\tools\arm-none-eabi\bin\ld.exe: ./Src/main.o: in function `main':
C:/Users/Pesquisa2/Documents/stm32/LM_STM32/Debug/../Src/main.c:55: undefined reference to `f_mkfs'
collect2.exe: error: ld returned 1 exit status
make: *** [makefile:68: laser_manual.elf] Error 1
"make -j8 all" terminated with exit code 2. Build might be incomplete.
How is this possible?
(Obs.: this are standard Elm Chan library)
Paths
I'm using STM32CubeMX for compilation and debugging. On properties, I set my C/C++ General/Paths and Symbols as following:
Includes: /laser_manual/FATFS/inc
Source Location: /laser_manual/FATFS
Tool Settings
MCU GCC Assembler:
-mcpu=cortex-m4 -g3 -DDEBUG -c -I"C:\Users\Pesquisa2\Documents\stm32\LM_STM32\FATFS\src" -x assembler-with-cpp --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb
MCU GCC Compiler:
-mcpu=cortex-m4 -std=gnu11 -g3 -DDEBUG -DSTM32 -DSTM32F4 -DSTM32F407ZGTx -c -I"C:\Users\Pesquisa2\STM32Cube\Repository\STM32Cube_FW_F4_V1.27.0\Drivers\CMSIS\Include" -I"C:\Users\Pesquisa2\STM32Cube\Repository\STM32Cube_FW_F4_V1.27.0\Drivers\CMSIS\Device\ST\STM32F4xx\Include" -I"C:\Users\Pesquisa2\Documents\stm32\LM_STM32\Inc\App" -I"C:\Users\Pesquisa2\Documents\stm32\LM_STM32\Inc\HAL" -I"C:\Users\Pesquisa2\Documents\stm32\LM_STM32\Inc" -I"C:\Users\Pesquisa2\Documents\stm32\LM_STM32\Src\Midware" -I"C:\Users\Pesquisa2\Documents\stm32\LM_STM32\Src\HAL" -I"C:\Users\Pesquisa2\Documents\stm32\LM_STM32\Src\App" -I"C:\Users\Pesquisa2\Documents\stm32\LM_STM32\Inc\Midware" -I"C:\Users\Pesquisa2\Documents\stm32\LM_STM32\FATFS\inc" -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb
MCU GCC Linker:
-mcpu=cortex-m4 -T"C:\Users\Pesquisa2\Documents\stm32\LM_STM32\STM32F407ZGTX_FLASH.ld" --specs=nosys.specs -Wl,-Map="${BuildArtifactFileBaseName}.map" -Wl,--gc-sections -static --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -u _printf_float -u _scanf_float -Wl,--start-group -lc -lm -Wl,--end-group
Solution
you need to make sure that two defines are:
FF_FS_READOLNY == 0
FF_USE_MKFS == 1
Some older versions use names without the FF
edit ffconf.h
Answered By - 0___________ Answer Checked By - David Marino (WPSolving Volunteer)