- 论坛徽章:
- 0
|
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 );
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/42908/showart_1813281.html |
|