Problems with Cube-generated Release build
I am having constant problems with building “Release” configuration of the Cube-generated projects. I’ve found many topics here describing similar problems, so it seems I am not alone. Posting here two workarounds that helped me, but would really like to hear from the developers on the nature of these and maybe see some bug fixes in the future.
Problem 1
in combined command line for C++ linker for “Release” build the following two entries
-specs=nosys.specs -specs=nano.specs
included twice, which causes an error. To work around this bug go to
Project->Properties->C/C++ Build->MCU G++ Linker->Miscellaneous
(for “Release” build only!) and remove these two settings from “Linker Flags”.
Go back to Project->Properties->C/C++ Build->MCU G++ Linker and check combined command line, it should now have these only once.
Problem 2
in combined command line for C++ compiler for “Release” build the following four entries
__weak=__attribute__((weak)) __packed=__attribute__((__packed__)) USE_HAL_DRIVER STM32F103xB
included twice, first with “-D” and then without “-D”. The second inclusion causes an error
syntax error: unexpected “(”
To work around this bug go to
Project->Properties->C/C++ General->Paths and Symbols->#Symbols
edit any value and apply changes. Then restore original value and apply again.
Return to Project->Properties->C/C++ Build->Settings->MCU G++ Compiler.
Check combined command line again, it should now have those entries only once with “-D”.
Problem 3
After two workarounds above the combined options for compilers are almost exactly the same, with the only exception -g3/-g flags, as expected. Regardless of this, the Release configuration still fails, with the compiler complaining about missing MCU specification. The comparison of the actual command lines passed to the MCU G++ Compiler shows that -D parameters are not passed in Release build.
Here are “All options” in the Project Properties dialog:
-mcpu=cortex-m3 -mthumb -mfloat-abi=soft -D__weak=__attribute__((weak)) -D__packed=__attribute__((__packed__)) -DUSE_HAL_DRIVER -DSTM32F103xB -I../Inc -I../Drivers/STM32F1xx_HAL_Driver/Inc -I../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32F1xx/Include -I../Drivers/CMSIS/Include -I"D:\eclipsePjt\SW4STM32_WS\libraries\Utilities" -I"D:\eclipsePjt\SW4STM32_WS\libraries\Utilities\platform\STM32F1" -Og -g -Wall -fmessage-length=0 -ffunction-sections -c -fno-exceptions -fno-rtti
And here is a command line:
Invoking: MCU G++ Compiler D:\eclipsePjt\SW4STM32_WS\projects\can_uart\Release arm-none-eabi-g++ -mcpu=cortex-m3 -mthumb -mfloat-abi=soft -I"D:/eclipsePjt/SW4STM32_WS/projects/can_uart/Inc" -I"D:/eclipsePjt/SW4STM32_WS/projects/can_uart/Drivers/STM32F1xx_HAL_Driver/Inc" -I"D:/eclipsePjt/SW4STM32_WS/projects/can_uart/Drivers/STM32F1xx_HAL_Driver/Inc/Legacy" -I"D:/eclipsePjt/SW4STM32_WS/projects/can_uart/Drivers/CMSIS/Device/ST/STM32F1xx/Include" -I"D:/eclipsePjt/SW4STM32_WS/projects/can_uart/Drivers/CMSIS/Include" -I"D:/eclipsePjt/SW4STM32_WS/libraries/Utilities" -I"D:/eclipsePjt/SW4STM32_WS/libraries/Utilities/platform/STM32F1" -Og -g -Wall -fmessage-length=0 -ffunction-sections -c -fno-exceptions -fno-rtti -MMD -MP -MF"Utilities/platform/STM32F1/can_impl.d" -MT"Utilities/platform/STM32F1/can_impl.o" -o "Utilities/platform/STM32F1/can_impl.o" "D:/eclipsePjt/SW4STM32_WS/libraries/Utilities/platform/STM32F1/can_impl.cpp"
I have no idea how to fix this one.
As a side note, this seems to be a problem with settings providers, not with cube generated project.