Hey, when I try to compile my code, I’m getting a weird linker error, that I sadly don’t know how to fix.
It points to the instantiation of a local static variable that’s wrapped in a singleton.
The compilation target that throws this error is the STM32F407VG target(target/STM32F407VG ), where the implementation lives. The header files live in include/ and the InterruptVectorTable.hpp lives in include/hal/
The last commit introduced the error.
arm-none-eabi-g++ -o .pio/build/stm32f407vg/firmware.elf -T stm32f405x6.ld -Wl,--gc-sections,--relax -mthumb -nostartfiles -nostdlib -mcpu=cortex-m4 .pio/build/stm32f407vg/src/main.o .pio/build/stm32f407vg/src/target/STM32F407VG/InterruptVectorTable.o .pio/build/stm32f407vg/src/target/STM32F407VG/startup_stm32f4xx.o .pio/build/stm32f407vg/src/target/STM32F407VG/system_stm32f4xx.o -L/Users/john/.platformio/platforms/ststm32/ldscripts -L.pio/build/stm32f407vg -Wl,--start-group -lc -lgcc -lm -lstdc++ -lnosys -Wl,--end-group
.pio/build/stm32f407vg/src/main.o: In function `main':
/Users/john/Documents/PlatformIO/Projects/Testing_MCB1768/include/hal/InterruptVectorTable.hpp:133: undefined reference to `__dso_handle'
/Users/john/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m/libc.a(lib_a-fini.o): In function `__libc_fini_array':
fini.c:(.text.__libc_fini_array+0x26): undefined reference to `_fini'
/Users/john/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/bin/ld: .pio/build/stm32f407vg/firmware.elf: hidden symbol `__dso_handle' isn't defined
/Users/john/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
*** [.pio/build/stm32f407vg/firmware.elf] Error 1
It’s not so bad. One of the undefined references is gone (success) but a new warning appeared. It’s just a warning that says -fno-use-cxa-atexit is okay for the C++ compiler but not for the C compiler. Unfortunately, I don’t know how to specify compiler options to the C compiler only.
The second undefined reference is still present, however:
fini.c:(.text.__libc_fini_array+0x26): undefined reference to `_fini'
Again, it’s related to cleanup when a program finishes, i.e. something not needed on an embedded device. Unfortunately, I have no idea which part of your code wants to use it. You might need to inspect all object files to find the one adding something to the .fini_array ELF section…
I found the solution, it’s not really related to those flags, but maybe a little bit. At least your help lead me to find the error. I was using empty destructors everywhere in case I would need them for some implementation. I guess I will not need them, as I guess static objects are not supposed to be ever destroyed in an embedded context.
Thus I removed the destructors and their “implementation” and it works fine now.
Thanks for being a great help like always in this forum!