The linker file is expected to be in the root directory instead of the subdirectory
The linker file is expected to be in the root directory instead of the subdirectory
I have a project that has to compile for two STM32 hardware platforms:
- the Nucleo-F446RE development board
- the STM32G051 microcontroller
The project is developed in VS Code.
The .ioc file has been moved from the root directory to two subdirectories:
./target/nucleo_f446re
./target/g051
In the file CMakePresets.json
{
"name": "nucleo_f446re",
"inherits": "default",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"STM32_TARGET": "nucleo_f446re"
},
"toolchainFile": "${sourceDir}/targets/nucleo_f446re/cmake/gcc-arm-none-eabi.cmake"
},
The gcc-arm-none-eabi.cmake file is generated by STM32CubeMX.
It contains the following line:
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -T \"${CMAKE_SOURCE_DIR}/STM32F446XX_FLASH.ld\"")
This means that the linker script is expected to be in the root directory of the project.
However, it is actually located in the corresponding subdirectory.
I fixed this by changing the line to:
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -T \"${CMAKE_CURRENT_LIST_DIR}/../STM32F446XX_FLASH.ld\"")
My questions are:
- Is this fix correct?
- Is there a better way to configure STM32CubeMX to generate the gcc-arm-none-eabi.cmake file correctly?
I am using STM32CubeMX version 6.16.1.
