ld

GNU linker

TLDR

Link object files
$ ld -o [output] [file1.o] [file2.o]
Link with library
$ ld -o [output] [file.o] -l[library]
Specify library path
$ ld -o [output] [file.o] -L[/path/to/lib] -l[name]
Link shared library
$ ld -shared -o [lib.so] [file.o]
Entry point
$ ld -e [main] -o [output] [file.o]
Verbose linking
$ ld -v -o [output] [file.o]

SYNOPSIS

ld [options] files

DESCRIPTION

ld is the GNU linker. It combines object files into executables or libraries.The linker resolves symbols and relocates code. It's typically invoked through gcc rather than directly.

PARAMETERS

FILES

Object files to link.
-o FILE
Output file name.
-l NAME
Link with library.
-L DIR
Library search path.
-shared
Create shared library.
-e SYMBOL
Entry point symbol.
-v
Verbose output.
--help
Display help information.

INSTALL

sudo apt install binutils
sudo dnf install binutils
sudo pacman -S binutils
sudo apk add binutils
sudo zypper install binutils
brew install binutils
nix profile install nixpkgs#binutils

CAVEATS

Usually called via gcc. Complex options. Platform-specific.

HISTORY

ld is the GNU project linker, part of binutils, providing linking for the GNU toolchain.

SEE ALSO

gcc(1), ld.gold(1), ldd(1), nm(1)