LinuxCommandLibrary

ld

GNU linker

TLDR

Link object files

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

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.

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)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community