Skip to main content
Associate
September 21, 2026
Solved

The linker file is expected to be in the root directory instead of the subdirectory

  • September 21, 2026
  • 5 replies
  • 49 views

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.

Best answer by Ghofrane GSOURI

Hello ​@rgpb 

Your change request has been escalated to the development team under ticket ID #0065933 for feasibility assessment and resolution. I will keep you posted on any updates.

THX

Ghofrane 

5 replies

Ghofrane GSOURI
ST Technical Moderator
September 21, 2026

Hello ​@rgpb 

Could you please try to use the latest version of STM32CubeMX6.18.1 instead of 6.16.1?

I will be waiting for your feedback.

THX

Ghofrane

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
rgpbAuthor
Associate
September 21, 2026

Hello Ghofrane, 

I have update to STM32CubeMX 6.18.1 
Apologies for not doing this sooner.

A small difference is that the file name uses lowercase letter for the XX

STM32CubeMX 6.16.1 
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -T \"${CMAKE_SOURCE_DIR}/STM32F446XX_FLASH.ld\"")

STM32CubeMX 6.18.1 
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -T \"${CMAKE_SOURCE_DIR}/STM32F446xx_FLASH.ld\"")

But still ${CMAKE_SOURCE_DIR} is used. 

Thanks, 
Robert

Ghofrane GSOURI
ST Technical Moderator
September 22, 2026

Hello ​@rgpb 

STM32CubeMX is generating the linker script in the project generation root 

which is why the original generated line assumes the linker file is at the project root.

If you later move the .ioc and generated files into subdirectories such as target/nucleo_f446re and target/g051, CubeMX does not automatically update that linker path to match your custom folder structure. In that context, your fix is correct: using ${CMAKE_CURRENT_LIST_DIR} makes the linker script path relative to the generated gcc-arm-none-eabi.cmake file, which is more appropriate for a target-specific layout than ${CMAKE_SOURCE_DIR}. The main caveat is that this file is generated by STM32CubeMX, so your modification may be overwritten the next time code is regenerated.

THX

Ghofrane

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
rgpbAuthor
Associate
September 22, 2026

Hello Ghofrane

Thank for your response. 

So this is a change request for STM32CubeMX
Is it possible when STM32CubeMX generates the "gcc-arm-none-eabi.cmake" file, it uses the ${CMAKE_CURRENT_LIST_DIR}/..
To find the linker file. 


Tanks,  
Robert
 

Ghofrane GSOURI
Ghofrane GSOURIBest answer
ST Technical Moderator
September 22, 2026

Hello ​@rgpb 

Your change request has been escalated to the development team under ticket ID #0065933 for feasibility assessment and resolution. I will keep you posted on any updates.

THX

Ghofrane 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.