It’s been a long time that dynamic link libraries, static libraries, static links, dynamic links, and recently run-time links have been messed up. Everyone knows that the static link is a compile-time link, the generated file is large, the dynamic link is a runtime link, and the generated file is small. I don't know everyone, or everyone thinks that they know... sometimes windows, sometimes linux, sometimes Aix, sometimes gcc, sometimes g++, sometimes cc, sometimes xlc, sometimes .so, sometimes .a, sometimes .dll sometimes .lib sometimes .o, too much inconsistency, too much trouble. Also, because of work, I often use Aix as the working environment. Some say that .so is a dynamic link library, and .a is a static link library, but it doesn't look like it on Aix. This weekend, I spent two days researching these problems on Aix, using vac's xlc and ccs ld. I can't say how much I know now, but at least not as confused as before. Do a summary now.
One, link file and link method. In fact, not carefully thinking about dynamic linking and dynamic linking is the main reason for my confusion. The reason why I think of this problem is to write a library a in the work, then I have to compile a, then write another library b, b depends on a, I have to compile b, in the process, I began to think, I used the link method when I compiled a. I want to use a now. What is a? So I began to distinguish between the link file and the link method, started the following experiment 1, using the library file libc.a, statically linked into the executable program hello.c
C code copy code #include <stdio.h> Int main() { printf("Hello, world!\ "); } #include <stdio.h>int main() {printf("Hello, world!\ ");}Run# xlc - o hello.o -c hello.c Generate the target file hello.o Run ld -o hello_s -bstatic hello.o -lc I want to statically link hello.o and libc.a and generate the executable hello_s. I didn't use xlc directly to generate executable files. I wanted to figure out each step. The price of the result is a lot of time and endless search. -bnso is telling ld static links. (You can also use the -E and -S parameters of xlc to look at the pre-processing and assembly files of hello.c, and then use as to compile the assembly file to generate the object file.) Result ld: 0711-327 WARNING: Entry point not found: __start Ld: 0711-244 ERROR: No csects or exported symbols have been saved. Here is not found __start, this __start looks a lot like a sub-process of the system. The reason for this error is because we did not add such a library /usr/lib/crt0.o when linking. If you use xlc to directly link statically, then this library should be added by xlc itself (this library seems to be a thread) Initialization related), you can use the nm command to view the symbol associated with this target file, which contains __start. So we run ld -o hello_s -bstatic hello.o -lc /usr/lib/crt0.o The result is that a lot of symbols can't be found, ld: 0711-224 WARNING: Duplicate symbol: .is_posix_tz ld: 0711- 224 WARNING: Duplicate symbol: .__icuinit ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information. ld: 0711-317 ERROR: Undefined symbol: __loadx ld: 0711-317 ERROR: Undefined symbol: _system_TB_config ld: 0711-317 ERROR: Undefined symbol: errno ld: 0711-317 ERROR: Undefined symbol: .___bzero ld: 0711-317 ERROR: Undefined symbol: smcr_timebase ld: 0711-317 ERROR: Undefined symbol: .___memmove ld: 0711-317 ERROR : Undefined symbol: .___memset ld: 0711-317 ERROR: Undefined symbol: _system_configuration ld: 0711-317 ERROR: Undefined symbol: disclaim ld: 0711-317 ERROR: Undefined symbol: kwritev ld: 0711-317 ERROR: Undefined symbol: kpwritev Ld: 0711-317 ERROR: Undefined symbol: kpwrite ld: 0711-317 ERROR: Undefined symbol: kwrite ld: 0711-317 ERROR: Undefined symbol: kopenx ... ld prompt -bloadmap to see the specific error message, so I run ld -o hello_s -bstatic hello.o -lc /usr/lib/crt0.o -bloadmap:out.txt and view the output file to get... ld: 0711- 318 ERROR: Undefined symbols were found. The following symbols are in error: Symbol Inpndx TY CL Source-File(Object-File) OR Import-File{Shared-object} RLD: Address Section Rld-type Referencing Symbol ----- -------------------------------------------------- --------------------------------------- __loadx [262] ER DS (/usr/lib /libc.a[shr.o]) 0006919c .data R_POS [1658] <__loadx> _system_TB_config [792] ER UA (/usr/lib/libc.a[shr.o]) 000691a8 .data R_POS [1664] < ;_system_TB_config> errno [8] ER UA (/usr/lib/libc.a[shr.o]) 00068e3c .data R_POS [1226] ... This is some of the definitions in shr.o in libc.a The symbol can't be found, so we solve this shr.o, run ar -x /usr/lib/libc.a shr.o to get shr.o, then ldd shr.o get the output shr.o needs: /unix /Usr/lib/libcrypt.a(shr.o) /usr/lib/libc.a(shr.o) this s Hr.o needs the above three libraries, libc.a we have included, then where to find /unix this library? The symbols that are not found now should be system calls. Check the ld manual to know that we need to import the symbol table /lib/syscalls.exp of the system call. So we run # ld -o hello_s -bstatic hello.o -lc /usr/lib/crt0.o -bI:/lib/The result of syscalls.exp still reports error # ld -o hello_s -bstatic hello.o -lc /usr/lib/crt0.o -bI:/lib/syscalls.exp ld: 0711-224 WARNING: Duplicate symbol: .open ld: 0711 -224 WARNING: Duplicate symbol: .openx ld: 0711-224 WARNING: Duplicate symbol: .is_posix_tz ld: 0711-224 WARNING: Duplicate symbol: .__icuinit ld: 0711-224 WARNING: Duplicate symbol: .send ld: 0711-224 WARNING: Duplicate symbol: .nrecvmsg
In Apple Mac OS and Microsoft Windows have supported multi-touch today, the Linux open source commun
Because the installation of debian uses a minimal installation, the default installation in Chinese,
According to the bus structure, it can be divided into a bus type and a non-bus type. As we often
Why should there be process priority? This does not seem to require too much explanation. After all,
Linux sar command using basic tutorial
CentOS Linux program self-start script
Introduction to jiffies in the Linux kernel and their effects
What if your Unix/Linux chmod file is canceled with the x attribute?
The difference between tty and console and terminal
Ld: cannot find /ubuntu/omnibook/sections.lds: No
How to use the SOFTETHER server under the Linux operating system
Perfect installation of Win7/XP dual system in one partition (1)
Git and Github first use basic tutorials
How to view the history of Win8 IE browser
WinXP upgrade Win7 installation failure how to solve? U disk loading system failure reason analysis
A brief introduction to Windows 7 Game Explorer
Win8 several background program switching methods
Windows 2008 system IE secrets
How to solve the binding of ip and MAC address under win7 to display ARP entry failure