The following content comes from the study and arrangement of network resources. If there is any infringement, please inform and delete it.
reference content
https://www.cnblogs.com/huqingyu/archive/2005/02/28/110468.html
1. Tool Introduction
ld is the GNU linker, which is used to link object files and library files into executable files or library files.
2. How to use
Through the man manual, we can see that the format of the tool is as follows.
ld [options] obj_file #[]表示该项是可选的,obj_file表示目标文件
(1) ld supports many options, only some commonly used options are listed here.
options | describe |
-e | Specifies the entry label for the program. |
-l libName | Specifies the library Name to link against. |
-L Directory | Increase the search path Directory for library files. |
-o FILE | Set the output filename to FILE. |
-r --relocateable |
Produce redirectable output. For example, to generate an output file that can be used again as input to 'ld', this is often called "partial linking", and this option is used when we need to link several small .o files into one .o file. |
Ttext address1 Tbss address2 Tdata address3 |
Specify the link address of the code segment as address1. Specify the link address of the bss segment as address2. Specify the link address of the data segment as address3. |
-T SCRIPTFILE --script=SCRIPTFILE |
Use SCRIPTFILE as a linker script. If SCRIPTFILE does not exist in the current directory, it will be searched in the directory specified by the -L option. Multiple -T options make the contents cumulative. There can be spaces between -T and SCRIPTFILE, or they can be next to each other. |
-nostdlib | Only those library paths specified explicitly on the command line are searched, library paths specified in link scripts (including link scripts specified on the command line) are ignored. |
-Bstatic -static -non_shared |
Shared libraries are not linked. This is only available on platforms that support shared libraries. The different forms of this option are for compatibility with different systems. You can use this option multiple times on the command line, and it affects the library search for the -l option that follows it. |
(2) The following are some examples.
- arm-linux-ld -Ttext 0X87800000 led.o -o led.elf #Specify the link address of the code segment as 0X87800000
- arm-linux-ld -Tlink.lds -o uart.elf $^ #Specify link script as link.lds