In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "Linux common command ld how to use", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "Linux common command ld how to use" this article.
Linux common commands ld command, a member of the binary toolset GNU Binutils, is a GNU linker for linking object files to libraries as executable files or library files
The command format ld [OPTIONS] OBJFILES option shows that the ld command supports many link options, but most of them are rarely used. Here are the options accepted by the GNU ld command.
-b specifies the format of the object code input file-Bstatic only uses static libraries-Bdynamic only uses dynamic libraries-Bsymbolic binds references to global symbols in shared libraries-c,-mri-script= is compatible with MRI linkers Ld accepts script files written by the MRI command language-- cref creates cross-reference tables-- even if a relocatable output file (using-r) is specified, it allocates space for common symbols. The script command "FORCE_COMMON_ALLOCATION" has the same effect-defsym creates the specified global symbol in the output file-demangle restores the symbol name in the error message-e uses the specified symbol as the initial execution point of the program-e uses the specified symbol as the initial execution point of the program-when creating a dynamically linked executable file for ELF format files Add all symbols to the dynamic symbol table-f,-auxiliary= for ELF format shared objects, set the DT_AUXILIARY name-F,-- filter= for ELF format shared objects, set the DT_FILTER name. This tells the dynamic linker that the symbol table of the shared object being created should be used as a filter for the symbol table of the shared object name. -g is ignored. Used to provide compatibility with other tools-h for shared objects in ELF format, set the DT_SONAME name-I,-dynamic-linker,-- dynamic-linker= to specify the dynamic linker. This makes sense only when generating ELF executables that depend on dynamic link libraries. The default dynamic linker is usually correct, and do not use this option unless you know what you are doing. -l,-- library= adds the specified library file to the list of files to be linked-L,-- library-path=searchdir adds the specified path to the directory list of the search base-M,-- print-map displays the link mapping For diagnostic purposes-Map=: outputs the link mapping to the specified file-m simulates the specified linker-NMagi muromagic specifies to read / write text and data segments-nmai Mui nmagic turns off page alignment of the section and disables links to shared libraries. If the output format supports Unix-style magic numbers, mark the output as "NMAGIC"-noinhibit-exec to generate the output file, even if a non-fatal link error occurs. In general, if the linker encounters an error during the linking process, it will not generate an output file. -no-keep-memory ld usually caches the symbol table of input files in memory to optimize memory usage. This option tells ld not to cache symbol tables. When linking large executables, if ld runs out of memory, you may need to use this option-O for a non-zero level of optimization, and ld will optimize the output. This operation can be time-consuming and should be used when generating the final results. -o,-- output= specifies the name of the output file-- oformat= specifies the binary format of the output file-- R _ r _ mai _ talk _ jubos = reads the symbol name and address from the specified file-r _ r _ M _ M _ relocatable generates relocatable output (called partial connection)-rpath= adds the specified directory to the runtime library search path-rpath-link= specifies the directory to search for run-time shared libraries-S -- strip-debug ignores debugger symbol information from the output file-- strip-debug ignores all symbol information from the output file-shared,-Bshareable creates a shared library-split-by-file [= size] creates additional segments up to size in the output file for each target file. Size defaults to 1-split-by-reloc [= count] to create additional segments in the output file at the specified length-- section-start== locates the specified segment-T at the address specified in the output file, and-- script= uses scriptfile as the linker script. This script replaces (rather than adds to) the default linker script for ld, so the script must specify everything required by the output file. If the script file does not exist in the current directory Ld will look in the directory specified by the-L option-Ttext= uses the specified address as the starting point of the text segment-Tdata= uses the specified address as the starting point of the data segment-Tbss= uses the specified address as the starting point of the bss segment-tfocus trace Meri displays their names-u,-- undefined= forces the specified symbol as an undefined symbol in the output file -V,-- version indicates ld version number-warn-common warns when one generic symbol is combined with another generic symbol-warn-constructors if no global constructor is used Warn-warn-once warns only once for each undefined symbol-warn-section-align warns if the output segment address is changed for alignment-whole-archive includes all files in the archive for the specified archive file-X,-discard-locals deletes all local temporary symbols-x,-discard-al deletes all local symbols 4. Common example (1) Link the target file to generate an executable file. Given the C++ target files test.o and main.o, the executable file test.out is generated.
Ld / usr/lib64/crt1.o / usr/lib64/crti.o / usr/lib64/crtn.o / usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtbegin.o / usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtend.o-L/usr/lib/gcc/x86_64-redhat-linux/4.8.5-L/usr/lib64-L/usr/lib-lstdc++-lm-lgcc_s-lc-lgcc main O test.o-o test.out because generating an executable file for C++ You need to rely on many system libraries and related object files, such as the C language library libc.a, so when using ld for linking, you need to pay attention to adding longer command options, otherwise a link error will be reported. Use the glisten +-v command to view the command options used by the last line of collect2 to learn about the dependencies required to generate executable text.
Gmail +-v main.o test.o... Usr/libexec/gcc/x86_64-redhat-linux/4.8.5/collect2-build-id-no-add-needed-eh-frame-hdr-hash-style=gnu-m elf_x86_64-dynamic-linker / lib64/ld-linux-x86-64.so.2 / usr/lib64/crt1.o / usr/lib64/crti.o / usr/lib64/crtn.o / usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtbegin.o / usr / lib/gcc/x86_64-redhat-linux/4.8.5/crtend.o-L/usr/lib/gcc/x86_64-redhat-linux/4.8.5-L/usr/lib64-L/usr/lib-lstdc++-lm-lgcc_s-lc-lgcc main.o test.o above are all the contents of the article "how to use Linux commands ld" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.