HiveBrain v1.2.0
Get Started
← Back to all entries
snippetbashTip

ld — Link object files together. More information: <https://sourceware.org/binutils/docs/ld.html>.

Submitted by: @import:tldr-pages··
0
Viewed 0 times
ldcommandobjectlinkfilesclimoretogether

Problem

How to use the ld command: Link object files together. More information: <https://sourceware.org/binutils/docs/ld.html>.

Solution

ld — Link object files together. More information: <https://sourceware.org/binutils/docs/ld.html>.

Link a specific object file with no dependencies into an executable:
ld {{path/to/file.o}} {{[-o|--output]}} {{path/to/output_executable}}


Link two object files together:
ld {{path/to/file1.o}} {{path/to/file2.o}} {{[-o|--output]}} {{path/to/output_executable}}


Dynamically link an x86_64 program to glibc (file paths change depending on the system):
ld {{[-o|--output]}} {{path/to/output_executable}} {{[-I|--dynamic-linker]}} /lib/ld-linux-x86-64.so.2 /lib/crt1.o /lib/crti.o -lc {{path/to/file.o}} /lib/crtn.o

Code Snippets

Link a specific object file with no dependencies into an executable

ld {{path/to/file.o}} {{[-o|--output]}} {{path/to/output_executable}}

Link two object files together

ld {{path/to/file1.o}} {{path/to/file2.o}} {{[-o|--output]}} {{path/to/output_executable}}

Dynamically link an x86_64 program to glibc (file paths change depending on the system)

ld {{[-o|--output]}} {{path/to/output_executable}} {{[-I|--dynamic-linker]}} /lib/ld-linux-x86-64.so.2 /lib/crt1.o /lib/crti.o -lc {{path/to/file.o}} /lib/crtn.o

Context

tldr-pages: common/ld

Revisions (0)

No revisions yet.