Code: Select all
c:/chibistudio/tools/gnu tools arm embedded/10.3 2021.07/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\ME\AppData\Local\Temp\ch.elf.GQwVbg.ltrans1.ltrans.o:(.rodata._ZTVN10chibios_rt10BaseThreadE+0x8): undefined reference to `__cxa_pure_virtual'
c:/chibistudio/tools/gnu tools arm embedded/10.3 2021.07/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\ME\AppData\Local\Temp\ch.elf.GQwVbg.ltrans1.ltrans.o:(.rodata._ZTVN10chibios_rt10BaseThreadE+0xc): undefined reference to `__cxa_pure_virtual'
c:/chibistudio/tools/gnu tools arm embedded/10.3 2021.07/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\ME\AppData\Local\Temp\ch.elf.GQwVbg.ltrans1.ltrans.o:(.rodata._ZTVN10chibios_rt16BaseStaticThreadILi128EEE+0x8): undefined reference to `__cxa_pure_virtual'
c:/chibistudio/tools/gnu tools arm embedded/10.3 2021.07/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\ME\AppData\Local\Temp\ch.elf.GQwVbg.ltrans1.ltrans.o:(.rodata._ZTVN10chibios_rt16BaseStaticThreadILi256EEE+0x8): undefined reference to `__cxa_pure_virtual'
collect2.exe: error: ld returned 1 exit status
I think that the "-O2" optimization is letting the compiler or linker recognize that there is no need for the __cxa_pure_virtual function and throw it out. Under the "-Og" or "-O0" optimization, the function symbols remain in the ch.elf translation unit, but it is not being actually included in syscalls.o.
In the current /os/various/cpp_wrappers/chcpp.mk file, syscalls.c is included in the ALLCSRC macro.
Code: Select all
CHCPPSRC = $(CHIBIOS)/os/various/syscalls.c
...
ALLCSRC += $(CHCPPSRC)
syscalls.c is compiled by $(CC) and not $(CPPC). With the default USE_OPT and USE_COPT, files that are compiled by $(CC) do not have __cplusplus set and so the __cxa_pure_virtual function is not included in the compiled syscall.o. The default rules.mk does not let you compile .c files with the c++ compiler.
What is the best solution for fixing this?
- Make a separate syscalls.cpp containing the __cxa_pure_virtual function?
- Fiddle with rules.mk to force $(CC) to call $(CPPC) or use __cplusplus macro?
- Always compile with "-O2"?
- Remove the #ifdef __cplusplus and include the __cxa_pure_virtual for everyone?