分类: LINUX
2007-07-21 15:14:39
1. A library is basically just an archive of object files 2. Libraries is made up of source files that contain just functions. It can be called statically or dynamically by programs.
1. Create c/c++ source files. 2. Compile the source files into object files. gcc -c3. create a library. ar crv libmylib.a objfile1.o objfile2.o objfile3.o 4. creates an index inside the library ranlib libmylib.a 5. When linking, specify where the library can be found gcc -o foo -L. -lmylib foo.o Note: When copying the library, use -p to preserve permissions.
1. Create a shared or dynamic library gcc -fPIC -c objfile1.c gcc -fPIC -c objfile2.c gcc -fPIC -c objfile3.c gcc -shared -o libmylib.so objfile1.o objfile2.o objfile3.o 2. Shared libraries dynamically access libraries at run-time. 3. dynamic libraries is through the LD_LIBRARY_PATH. export LD_LIBRARY_PATH=/usr/local/lib:${LD_LIBRARY_PATH} 4. ldd - print shared library dependencies
see which shared libraries are required by a program Ex: ldd program libc.so.6 => /lib/libc.so.6 (0x4002a000) /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
list the symbols in object file Ex: nm client_down 00403010 b .bss ... 00404000 i .idata$2 ... 00402000 r .rdata 004013e0 t .text ... 00401720 T _GetModuleHandleA@4 ... 004040ac i hname 00401326 t probe