MacOS equivalent for Ubuntu Linker (ld) command?
I'm following some tutorials from 2015, and in it you run this Linker command:
ld -T linker.ld -melf_i386 loader.o -o kernel.elf
I get this error:
ld: unknown option: -T
I tried to replace it with ld --script=linker.ld -melf_i386 loader.o -o kernel.elf
, but this error: ld: unknown option: --script=linker.ld
After now looking through man ld
, it seems neither of these are options. This tutorial was designed for Ubuntu, what would be the MacOS equivalent?
If it matters, I am on an Intel Big Sur machine.
Linker scripts can be used with the GNU version of ld
to customise how you want your program to be linked. Essentially not all customizations can be made with command line arguments, and instead you specify them in a linker script.
The ld
command on macOS on the other hand allows you to specify all the possible customizations through the command line arguments. Therefore linker scripts are not used and not supported.
If you really want to find an "equivalent" option to -T
, it would be @
. You can go ld @file [...]
and the contents of the file named file
will be added to the command line arguments. It does not give you further possibilities for customisation than those already available as command line arguments.
Note that linker scripts made for the GNU version of ld
cannot be used with the standard macOS supplied version of ld
.