'Current Directory' search path for INCLUDE in GNU linker (ld)?

Viewed 1060

I have broken out the MEMORY{} command of my linker script into a separate file memmap.ld in order to share it between projects (bootloader and target firmware). The file is currently located in the same directory as the main linker script and I include it using the line

INCLUDE memmap.ld

from my main .ld script however this does not work and I get the error

ld.exe: cannot open linker script file memmap.ld: No such file or directory

when building. The section of the ld manual dealing with the INCLUDE filename command reads

Include the linker script filename at this point. The file will be searched for in the current directory, and in any directory specified with the ā€˜-L’ option. You can nest calls to INCLUDE up to 10 levels deep. You can place INCLUDE directives at the top level, in MEMORY or SECTIONS commands, or in output section descriptions.

What is up with this? Is the current directory taken from the current script, executable, some other external parameter?

Am using the ST build of the GNU Linker distributed with the 64 bit Windows STM32CubeIDE if it makes any difference.

1 Answers

It appears the matching of .ld scripts within the current directory when using INCLUDE only compares with script names introduced via either '-L searchdir' or '-T scriptfile'.

[i.e. the LD program doesn't do a file system search but instead searches the list of scripts provided during invocation (or at least behaves as such) ].

My case in point when using STM32CubeIDE only provides the option to provide a single loader script via the -T option within project system (while Eclipse Embedded CDT which ST bases it's tools on allows multiple files to be passed by -T) required the addition of the folder containing both my scripts using the -L option (from the Libraries subsection of the Linker project properties).

Once the script I was referencing inside LD was being passed through the build system by including the directory location in the command line the 'current directory' did resolve to that of the script doing the inclusion.

Related