Chinaunix首页 | 论坛 | 博客
  • 博客访问: 370788
  • 博文数量: 66
  • 博客积分: 3201
  • 博客等级: 中校
  • 技术积分: 695
  • 用 户 组: 普通用户
  • 注册时间: 2007-07-04 11:17
文章分类

全部博文(66)

文章存档

2016年(1)

2014年(1)

2012年(1)

2011年(2)

2010年(18)

2009年(42)

2008年(1)

分类: LINUX

2009-02-04 23:25:39

chapter 06.Building Static Libraries
we use the ar command to build our library (libmyrand.a). The cru options are a standard set of options for creating or adding to an archive. The c option specifies to create the static library (unless it already exists, in which case the option is ignored). The r option tells ar to replace existing objects in the static library (if they already exist). Finally, the u option is a safety option to specify that objects are replaced in the archive only if the objects to be inserted are newer than existing objects in the archive (of the same name).

In this example, we use nm to print the symbols within the shared library, but then only emit those with the tag " T " to stdout (those symbols that are part of the .text section, or code segments). We also use the -n option to sort the output numerically by address, rather than the default, which is alphabetically by symbol name. This gives us relative address information within the library; if we wanted to know the specific sizes of these .text sections, we could use the -S option, as:

$ nm -n -S /usr/local/lib/libmyrand.so | grep " T "
00000608 T _init
0000074c 00000036 T initRand
00000784 0000003a T getSRand
000007be 00000050 T getRand
00000844 T _fini
$

From this example, we can see that the initRand is located at relative offset 0x74c in the library and its size is 0¥36 (decimal 54) bytes. Many other options are available; the nm mainpage provides more detail on this.


Dynamic Library APIs

    #include 
    void *dlopen( const char *filename, int flag );
    const char *dlerror( void );
    void *dlsym( void *handle, char *symbol );
    int dlclose( void *handle );
阅读(651) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~