← 返回命令列表

Linux command

ld.gold 命令

文件

复制后可按需替换文件名、目录或参数。

常用示例

Link object files

ld.gold -o [output] [file1.o] [file2.o]

Link against a system library

ld.gold -o [output] [file.o] -l[library]

Use gold via gcc

gcc -fuse-ld=gold -o [output] [file.c]

Build a shared library

ld.gold -shared -o [lib.so] [file.o]

Cap the number of threads

ld.gold --threads --thread-count=[4] -o [output] [*.o]

Enable incremental linking

ld.gold --incremental -o [output] [*.o]

说明

ld.gold (commonly invoked as gold) is a high-performance ELF-only linker written for GNU binutils. Compared to the traditional GNU ld it is significantly faster on large C++ codebases, thanks to parallel processing of input objects, locality-aware symbol resolution, and an internal design tuned for modern multi-core CPUs. Most projects invoke gold indirectly through the compiler driver with -fuse-ld=gold. It accepts the GNU ld command line for the most common options, which makes drop-in adoption straightforward. Specialized features like --incremental linking, plugin support (LTO), and DWARF-aware output are exposed through gold-specific options.

参数

-o _FILE_
Write the linked output to _FILE_.
-l _NAME_
Search for libNAME.so or libNAME.a in the link path.
-L _DIR_
Add _DIR_ to the library search path.
-shared
Produce a shared object instead of an executable.
-static
Produce a fully statically linked executable.
--threads, --no-threads
Enable or disable multi-threaded link stages.
--thread-count _N_
Use _N_ worker threads when --threads is on.
--incremental
Re-use a previous link's output for unchanged inputs.
--gc-sections
Discard unreferenced sections from the output.
-r, --relocatable
Produce a relocatable object (partial link).
--help
Display help information.

FAQ

What is the ld.gold command used for?

ld.gold (commonly invoked as gold) is a high-performance ELF-only linker written for GNU binutils. Compared to the traditional GNU ld it is significantly faster on large C++ codebases, thanks to parallel processing of input objects, locality-aware symbol resolution, and an internal design tuned for modern multi-core CPUs. Most projects invoke gold indirectly through the compiler driver with -fuse-ld=gold. It accepts the GNU ld command line for the most common options, which makes drop-in adoption straightforward. Specialized features like --incremental linking, plugin support (LTO), and DWARF-aware output are exposed through gold-specific options.

How do I run a basic ld.gold example?

Run `ld.gold -o [output] [file1.o] [file2.o]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -o _FILE_ do in ld.gold?

Write the linked output to _FILE_.