← 返回命令列表

Linux command

ld 命令

文件

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

常用示例

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]

说明

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.

参数

-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.

FAQ

What is the ld command used for?

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.

How do I run a basic ld example?

Run `ld -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?

Output file name.