Chinaunix首页 | 论坛 | 博客
  • 博客访问: 134416
  • 博文数量: 51
  • 博客积分: 2500
  • 博客等级: 少校
  • 技术积分: 540
  • 用 户 组: 普通用户
  • 注册时间: 2007-07-21 12:33
文章分类

全部博文(51)

文章存档

2011年(1)

2010年(5)

2009年(1)

2008年(12)

2007年(32)

我的朋友

分类: LINUX

2007-07-21 15:14:39

Library

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.

Creating Static Libraries

1. Create c/c++ source files.
2. Compile the source files into object files.
   gcc -c 
3. 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. 

Creating Dynamical Libraries

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

some utilities

ldd

 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)
 

nm

 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

阅读(422) | 评论(0) | 转发(0) |
0

上一篇:Emacs advanced

下一篇:login to linux server hints

给主人留下些什么吧!~~