Hi,
I am currently working with the frdm K22F SDK, more precisley the dspi_half_duplex_int_master. This is a C Project and I want to integrate C++ files into it. To execute it, I decided to change the main file from .c to .cpp which leads to the following error when building it.
make -r -j8 all
Building target: frdmk22f_dspi_half_duplex_int_master.axf
Invoking: MCU Linker
arm-none-eabi-gcc -nostdlib -Xlinker -Map="frdmk22f_dspi_half_duplex_int_master.map" -Xlinker --gc-sections -Xlinker -print-memory-usage -Xlinker --sort-section=alignment -Xlinker --cref -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -T frdmk22f_dspi_half_duplex_int_master_Debug.ld -o "frdmk22f_dspi_half_duplex_int_master.axf" ./utilities/fsl_assert.o ./utilities/fsl_debug_console.o ./startup/startup_mk22f51212.o ./source/semihost_hardfault.o ./drivers/fsl_clock.o ./drivers/fsl_common.o ./drivers/fsl_dspi.o ./drivers/fsl_gpio.o ./drivers/fsl_lpuart.o ./drivers/fsl_smc.o ./drivers/fsl_uart.o ./device/system_MK22F51212.o ./component/uart/fsl_adapter_uart.o ./component/lists/fsl_component_generic_list.o ./board/board.o ./board/clock_config.o ./board/pin_mux.o
Memory region Used Size Region Size %age Used
PROGRAM_FLASH: 7912 B 512 KB 1.51%
c:/nxp/mcuxpressoide_11.3.0_5222/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.3.0.202008311133/tools/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/bin/ld.exe: c:/nxp/mcuxpressoide_11.3.0_5222/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.3.0.202008311133/tools/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard\libcr_semihost_nf.a(_cr__main.o): in function `__main':
SRAM_UPPER: 8424 B 64 KB 12.85%
_cr__main.c:(.text.__main+0xa): undefined reference to `main'
collect2.exe: error: ld returned 1 exit status
SRAM_LOWER: 0 GB 64 KB 0.00%
make: *** [makefile:39: frdmk22f_dspi_half_duplex_int_master.axf] Error 1
"make -r -j8 all" terminated with exit code 2. Build might be incomplete.
From these posts: here and here it seems to me that I need to change something with the linker files. But I don't know for sure if that is the same problem.
Thanks in advance!
Solved! Go to Solution.
It all depends how you have 'migrated' your projects.
Keep in mind that the project nature needs to match your settings, see https://mcuoneclipse.com/2020/07/11/from-c-to-c-converting-eclipse-c-projekts/
On top of that, it all depends how you organize your calling conventions: keep in mind that main is a special symbol, plus for calling interfaces implemented in C from C++ you need to add an 'extern "C"' to manage the name mangling.
And don't forget the thing about the global constructor calls.
I hope this helps,
Erich
Hi Erich,
thanks for the quick reply. Yes it helped! I followed the steps from the link you posted and also verified for the global constructor calls. I still had some errors but they disappeared after I changed the lib from NewlibNano(none) to NewlibNano(nohost). So everything builds now fine.
However, now I don't get any output in the console now, that I got before (like "Hello World"). Do you have any idea what could cause this?
It all depends how you have 'migrated' your projects.
Keep in mind that the project nature needs to match your settings, see https://mcuoneclipse.com/2020/07/11/from-c-to-c-converting-eclipse-c-projekts/
On top of that, it all depends how you organize your calling conventions: keep in mind that main is a special symbol, plus for calling interfaces implemented in C from C++ you need to add an 'extern "C"' to manage the name mangling.
And don't forget the thing about the global constructor calls.
I hope this helps,
Erich
Thanks for the quick help! Do you know a solution regarding the console-output problem I now have? (see the wrongly placed reply by me)
Ok, I found that the problem was that I was using the nohost library variant. I swithed to semihost and now it works.