Compilation problems - I'm totally stuck!

Hello!

I’m having a hard time compiling a project.

I’m getting the error:

.pio/build/dueUSB/src/M5.ino.cpp.o: In function `setup':
M5.ino.cpp:(.text.setup+0x14): undefined reference to `tmc5072_init(TMC5072TypeDef*, unsigned char, ConfigurationTypeDef*, long const*)'

that I do not understand because I can see in the verbose output that my library is being compiled:

arm-none-eabi-g++ -o .pio/build/dueUSB/src/M5.ino.cpp.o -c -fno-rtti -fno-exceptions -std=gnu++11 -fno-threadsafe-statics -Os -ffunction-sections -fdata-sections -Wall -mcpu=cortex-m3 -mthumb -nostdlib --param max-inline-insns-single=500 -DPLATFORMIO=50204 -D__SAM3X8E__ -DARDUINO_SAM_DUE -DARDUINO=10805 -DF_CPU=84000000L -DUSBCON -DUSB_VID=0x2341 -DUSB_PID=0x003E "-DUSB_PRODUCT=\"Arduino Due\"" -DUSB_MANUFACTURER=\"Arduino\" -DARDUINO_ARCH_SAM -Iinclude -Isrc -Ilib/TMC5072 -I/Users/thomasfeldmann/.platformio/packages/framework-arduino-sam/cores/arduino -I/Users/thomasfeldmann/.platformio/packages/framework-arduino-sam/system/libsam -I/Users/thomasfeldmann/.platformio/packages/framework-arduino-sam/system/CMSIS/CMSIS/Include -I/Users/thomasfeldmann/.platformio/packages/framework-arduino-sam/system/CMSIS/Device/ATMEL -I/Users/thomasfeldmann/.platformio/packages/framework-arduino-sam/variants/arduino_due_x src/M5.ino.cpp
arm-none-eabi-gcc -o .pio/build/dueUSB/lib011/TMC5072/TMC5072.c.o -c -std=gnu11 -Os -ffunction-sections -fdata-sections -Wall -mcpu=cortex-m3 -mthumb -nostdlib --param max-inline-insns-single=500 -DPLATFORMIO=50204 -D__SAM3X8E__ -DARDUINO_SAM_DUE -DARDUINO=10805 -DF_CPU=84000000L -DUSBCON -DUSB_VID=0x2341 -DUSB_PID=0x003E "-DUSB_PRODUCT=\"Arduino Due\"" -DUSB_MANUFACTURER=\"Arduino\" -DARDUINO_ARCH_SAM -Ilib/TMC5072 -I/Users/thomasfeldmann/.platformio/packages/framework-arduino-sam/cores/arduino -I/Users/thomasfeldmann/.platformio/packages/framework-arduino-sam/system/libsam -I/Users/thomasfeldmann/.platformio/packages/framework-arduino-sam/system/CMSIS/CMSIS/Include -I/Users/thomasfeldmann/.platformio/packages/framework-arduino-sam/system/CMSIS/Device/ATMEL -I/Users/thomasfeldmann/.platformio/packages/framework-arduino-sam/variants/arduino_due_x lib/TMC5072/TMC5072.c
arm-none-eabi-gcc -o .pio/build/dueUSB/lib011/TMC5072/helpers/CRC.c.o -c -std=gnu11 -Os -ffunction-sections -fdata-sections -Wall -mcpu=cortex-m3 -mthumb -nostdlib --param max-inline-insns-single=500 -DPLATFORMIO=50204 -D__SAM3X8E__ -DARDUINO_SAM_DUE -DARDUINO=10805 -DF_CPU=84000000L -DUSBCON -DUSB_VID=0x2341 -DUSB_PID=0x003E "-DUSB_PRODUCT=\"Arduino Due\"" -DUSB_MANUFACTURER=\"Arduino\" -DARDUINO_ARCH_SAM -Ilib/TMC5072 -I/Users/thomasfeldmann/.platformio/packages/framework-arduino-sam/cores/arduino -I/Users/thomasfeldmann/.platformio/packages/framework-arduino-sam/system/libsam -I/Users/thomasfeldmann/.platformio/packages/framework-arduino-sam/system/CMSIS/CMSIS/Include -I/Users/thomasfeldmann/.platformio/packages/framework-arduino-sam/system/CMSIS/Device/ATMEL -I/Users/thomasfeldmann/.platformio/packages/framework-arduino-sam/variants/arduino_due_x lib/TMC5072/helpers/CRC.c
arm-none-eabi-gcc -o .pio/build/dueUSB/lib011/TMC5072/helpers/Functions.c.o -c -std=gnu11 -Os -ffunction-sections -fdata-sections -Wall -mcpu=cortex-m3 -mthumb -nostdlib --param max-inline-insns-single=500 -DPLATFORMIO=50204 -D__SAM3X8E__ -DARDUINO_SAM_DUE -DARDUINO=10805 -DF_CPU=84000000L -DUSBCON -DUSB_VID=0x2341 -DUSB_PID=0x003E "-DUSB_PRODUCT=\"Arduino Due\"" -DUSB_MANUFACTURER=\"Arduino\" -DARDUINO_ARCH_SAM -Ilib/TMC5072 -I/Users/thomasfeldmann/.platformio/packages/framework-arduino-sam/cores/arduino -I/Users/thomasfeldmann/.platformio/packages/framework-arduino-sam/system/libsam -I/Users/thomasfeldmann/.platformio/packages/framework-arduino-sam/system/CMSIS/CMSIS/Include -I/Users/thomasfeldmann/.platformio/packages/framework-arduino-sam/system/CMSIS/Device/ATMEL -I/Users/thomasfeldmann/.platformio/packages/framework-arduino-sam/variants/arduino_due_x lib/TMC5072/helpers/Functions.c

The project is here:
https://www.dropbox.com/s/kbfgq4ejy79b989/pio-tmc5072.zip?dl=1

Where did I go wrong?

Using .c files from your .ino/.cpp files require that the header for TMC5072.c (TMC5072.h?) marks the function as extern "C". Otherwise C++ name-mangling will cause the function to not be found. See e.g. here. So, you did that, right?

Oh wow, thank you. That’s it. Renaming my .c to .cpp fixes everything. That was quite a time sink, and what a dumb one.

Have a great day!