Enable to link C++ project autogenerated by CubeMX

Discussions concerning TrueSTUDIO for STM32 9.0.0 and later versions.

Moderators: Markus Girdland, Mattias Norlander

Posts: 2
Joined: Tue Feb 12, 2019 11:23 am

Enable to link C++ project autogenerated by CubeMX

Postby adjo » Tue Feb 12, 2019 1:18 pm


I'm a C/C++ developper and I'm new on STM32 with Cube MX and TrueStudio.
But I have knowledge in Eclipse!

What I want:
Develop all my source code in C++ on STM32, I want to generate the config STM32 file from CubeMX.

Proccess I have followed:
- Using CubeMX I have set all the STM32L431RB hardware config and peripherals
- Generate the code using Cube MX (with "Toolchain/IDE = TrueSTUDIO" and "Generate Under Root")
- Open the generated project using TrueSTUDIO
-> At this step the source code compile well under TrueStudio
- Right clic on the project / New / "Convert to a C/C++ Project (Adds C/C++ Nature)"
- Add the path directories in C++ Compiler settings (the same as the C Compiler)
-> At this time I have a linker issue

My Issue:

Code: Select all

arm-atollic-eabi-g++ -o test.elf Core\Src\adc.o Core\Src\can.o Core\Src\gpio.o Core\Src\i2c.o Core\Src\iwdg.o Core\Src\main.o Core\Src\rng.o Core\Src\rtc.o Core\Src\stm32l4xx_hal_msp.o Core\Src\stm32l4xx_hal_timebase_tim.o Core\Src\stm32l4xx_it.o Core\Src\system_stm32l4xx.o Core\Src\tim.o Core\Src\usart.o Core\tyva\Drivers\AFE\cAfe.o Core\tyva\Drivers\AFE\cBq769x0.o Core\tyva\Drivers\CAN\cCan.o Core\tyva\Drivers\RTC\cRtc.o Core\tyva\Drivers\cDriver.o Core\tyva\tools\cCrc.o Drivers\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal.o Drivers\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_adc.o Drivers\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_adc_ex.o Drivers\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_can.o Drivers\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_cortex.o Drivers\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_dma.o Drivers\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_dma_ex.o Drivers\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_flash.o Drivers\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_flash_ex.o Drivers\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_flash_ramfunc.o Drivers\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_gpio.o Drivers\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_i2c.o Drivers\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_i2c_ex.o Drivers\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_iwdg.o Drivers\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_pwr.o Drivers\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_pwr_ex.o Drivers\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_rcc.o Drivers\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_rcc_ex.o Drivers\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_rng.o Drivers\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_rtc.o Drivers\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_rtc_ex.o Drivers\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_tim.o Drivers\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_tim_ex.o Drivers\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_uart.o Drivers\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_uart_ex.o startup\startup_stm32l431xx.o -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -T../STM32L431RB_FLASH.ld -specs=nosys.specs -static -Wl,-cref,-u,Reset_Handler -Wl,-Map=test.map -Wl,--gc-sections -Wl,--defsym=malloc_getpagesize_P=0x1000 -Wl,--start-group -lc -lm -lstdc++ -lsupc++ -Wl,--end-group
d:/program files (x86)/truestudio for stm32 9.2.0/armtools/bin/../lib/gcc/arm-atollic-eabi/6.3.1/../../../../arm-atollic-eabi/bin/ld.exe: test.elf section `.text' will not fit in region `FLASH'
d:/program files (x86)/truestudio for stm32 9.2.0/armtools/bin/../lib/gcc/arm-atollic-eabi/6.3.1/../../../../arm-atollic-eabi/bin/ld.exe: region `FLASH' overflowed by 155680 bytes

For sure I made something wrong but I don't know how to fix this issue.
I understand the issue: I need to map the .text section in the right section but where (in which file) ? And why that auto-generated file is wrong ?

Thanks in advance

Markus Girdland
Posts: 149
Joined: Thu May 11, 2017 11:27 am

Re: Enable to link C++ project autogenerated by CubeMX

Postby Markus Girdland » Tue Feb 12, 2019 2:07 pm

Make sure you go into your projects properties -> C/C++ Build -> Settings -> Tool Settings and copy your C Linkers settings (from Libraries for example) to the corresponding settings of the C++ settings.

Also go to C/C++ General -> Paths and Symbols.
Make sure to check the includes and symbols tab there as well.

I believe there could still be a bug with the symbols tab, however. As reported here:
https://community.st.com/s/question/0D5 ... ymbols-tab

Posts: 2
Joined: Tue Feb 12, 2019 11:23 am

Re: Enable to link C++ project autogenerated by CubeMX

Postby adjo » Thu Feb 14, 2019 3:46 pm

Thanks so much for your help.

I have solved the issue by following your link and restart the TrueSTUDIO project from sratch and import properly the CubeMX generated files (as explaine in the link).


Return to “TrueSTUDIO for STM32 discussions”

Who is online

Users browsing this forum: No registered users and 1 guest