I've been reading up on Petit FatFS and trying to implement it for a few days now with no success. Throughout my trials one thing I keep encountering is 'undefined reference' errors. Today I recreated the issue as follows...
- Created a new project in Atmel Studio 7
- Downloaded Petit FatFS source (pff3a.zip) from elm-chan.org and unzip it into the same folder as my main.c
- Add #include's as shown below
- call disk_initialize
#include <avr/io.h> #include "diskio.h" #include "pff.h" int main(void) { disk_initialize(); while (1) {} }
The result is...
Error ld returned 1 exit status GccApplication1 collect2.exe 0 Error recipe for target 'GccApplication1.elf' failed GccApplication1 D:\AVR-FatFS-Petit-test2\GccApplication1\Debug\Makefile 118 Error undefined reference to `disk_initialize' GccApplication1 D:\AVR-FatFS-Petit-test2\GccApplication1\main.c 15
Output is...
------ Build started: Project: GccApplication1, Configuration: Debug AVR ------ Build started. Project "GccApplication1.cproj" (default targets): Target "PreBuildEvent" skipped, due to false condition; ('$(PreBuildEvent)'!='') was evaluated as (''!=''). Target "CoreBuild" in file "C:\Program Files (x86)\Atmel\Studio\7.0\Vs\Compiler.targets" from project "D:\AVR-FatFS-Petit-test2\GccApplication1\GccApplication1.cproj" (target "Build" depends on it): Task "RunCompilerTask" Shell Utils Path C:\Program Files (x86)\Atmel\Studio\7.0\shellUtils C:\Program Files (x86)\Atmel\Studio\7.0\shellUtils\make.exe all --jobs 8 --output-sync main.o: In function `main': D:\AVR-FatFS-Petit-test2\GccApplication1\main.c(15,1): error: undefined reference to `disk_initialize' collect2.exe(0,0): error: ld returned 1 exit status make: *** [GccApplication1.elf] Error 1 Building target: GccApplication1.elf Invoking: AVR/GNU Linker : 5.4.0 "C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe" -o GccApplication1.elf main.o pff.o -Wl,-Map="GccApplication1.map" -Wl,--start-group -Wl,-lm -Wl,--end-group -Wl,--gc-sections -mmcu=attiny85 -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATtiny_DFP\1.3.172\gcc\dev\attiny85" D:\AVR-FatFS-Petit-test2\GccApplication1\Debug\Makefile(118,1): error: recipe for target 'GccApplication1.elf' failed The command exited with code 2. Done executing task "RunCompilerTask" -- FAILED. Done building target "CoreBuild" in project "GccApplication1.cproj" -- FAILED. Done building project "GccApplication1.cproj" -- FAILED. Build FAILED. ========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========
In Atmel Studio, main.c, I can right-click on disk_initialize() and select 'Goto Implementation' where it then correctly shows the two references to the diskio.h and diskio.c files. Also when I begin typing disk_initialize it comes up as a suggestion. It's as if the editor see's it but the compiler doesn't. I have tried this on two computers and with the last 3 versions of Petit FatFS source. I know there's more to implementing a functional Petit FatFS than this, such as disk access, but it seems this basic test should not throw an undefined reference. Am I missing something?
Much appreciated.