1、查看库文件是由哪个软件包提供的
空闲时打开/usr/lib目录(因为我知道这个目录下放着一些库文件,是我们开发者可以利用的)想看看我的系统中有哪些库。
看到一个libz.so,于是用命令查看:
dpkg -S /usr/lib/libz.so |
zlib1g-dev: /usr/lib/libz.so |
apt-cache show zlib1g-dev |
Description: compression library - development zlib is a library implementing the deflate compression method found in gzip and PKZIP. This package includes the development support files. Bugs: mailto:[email protected] Origin: Ubuntu |
dpkg -L zlib1g-dev |
/. /usr /usr/lib /usr/lib/libz.a /usr/include /usr/include/zlib.h /usr/include/zconf.h /usr/share /usr/share/doc /usr/share/doc/zlib1g-dev /usr/share/doc/zlib1g-dev/examples /usr/share/doc/zlib1g-dev/examples/example.c.gz /usr/share/doc/zlib1g-dev/examples/contrib.tar.gz /usr/share/doc/zlib1g-dev/examples/minigzip.c.gz /usr/share/doc/zlib1g-dev/changelog.gz /usr/share/doc/zlib1g-dev/FAQ.gz /usr/share/doc/zlib1g-dev/README.gz /usr/share/doc/zlib1g-dev/copyright /usr/share/doc/zlib1g-dev/changelog.Debian.gz /usr/share/doc/zlib1g-dev/algorithm.txt.gz /usr/share/man /usr/share/man/man3 /usr/share/man/man3/zlib.3.gz /usr/lib/libz.so |
nm -D /usr/lib/libz.so |
00001810 T adler32 00001ad0 T adler32_combine 00013b30 A __bss_start U clearerr 00001c70 T compress 00001ba0 T compress2 00001b80 T compressBound 00001cd0 T crc32 00002320 T crc32_combine w __cxa_finalize 00005da0 T deflate 00005150 T deflateBound 00004bb0 T deflateCopy 000107e0 R deflate_copyright 00004890 T deflateEnd 00005640 T deflateInit_ 00005360 T deflateInit2_ 00006b80 T deflateParams 00004810 T deflatePrime 000051c0 T deflateReset 00004fe0 T deflateSetDictionary 000047e0 T deflateSetHeader 00004850 T deflateTune 00010820 R _dist_code 00013b30 A _edata 00013b34 A _end U __errno_location U fclose U fdopen U feof U ferror U fflush 0000e784 T _fini U fopen U fprintf U fputc U fread U free U fseek U ftell U fwrite 00001cb0 T get_crc_table w __gmon_start__ 00002570 T gzclearerr 00002b50 T gzclose 00002550 T gzdirect 00003ba0 T gzdopen 00002520 T gzeof 000025b0 T gzerror 00002d40 T gzflush 000046c0 T gzgetc 00004640 T gzgets 00003c20 T gzopen 00002a10 T gzprintf 00002900 T gzputc 000028c0 T gzputs 00003c40 T gzread 00002950 T gzrewind 00004410 T gzseek 00002ab0 T gzsetparams 00004600 T gztell 000024d0 T gzungetc 000027d0 T gzwrite 0000a490 T inflate 0000c4e0 T inflateBack 0000c490 T inflateBackEnd 0000c390 T inflateBackInit_ 0000a000 T inflateCopy 00012720 R inflate_copyright 00009f40 T inflateEnd 0000e1c0 T inflate_fast 00009fa0 T inflateGetHeader 00009f00 T inflateInit_ 00009df0 T inflateInit2_ 00009da0 T inflatePrime 00009d00 T inflateReset 0000a380 T inflateSetDictionary 0000c1a0 T inflateSync 00009fd0 T inflateSyncPoint 0000d770 T inflate_table 000013d0 T _init w _Jv_RegisterClasses 00010a20 R _length_code U malloc U memcpy U memset U sprintf U __stack_chk_fail U strcat U strcpy U strerror U strlen 00008390 T _tr_align 00009240 T _tr_flush_block 000074e0 T _tr_init 00008210 T _tr_stored_block 00007c10 T _tr_tally 00004710 T uncompress U vsnprintf 00009cd0 T zcalloc 00009ca0 T zcfree 00013900 D z_errmsg 00009c70 T zError 00009c60 T zlibCompileFlags 00009c40 T zlibVersion |
nm -D /usr/lib/libz.so | grep gz |
00002570 T gzclearerr 00002b50 T gzclose 00002550 T gzdirect 00003ba0 T gzdopen 00002520 T gzeof 000025b0 T gzerror 00002d40 T gzflush 000046c0 T gzgetc 00004640 T gzgets 00003c20 T gzopen 00002a10 T gzprintf 00002900 T gzputc 000028c0 T gzputs 00003c40 T gzread 00002950 T gzrewind 00004410 T gzseek 00002ab0 T gzsetparams 00004600 T gztell 000024d0 T gzungetc 000027d0 T gzwrite |
ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); /* Opens a gzip (.gz) file for reading or writing. The mode parameter is as in fopen ("rb" or "wb") but can also include a compression level ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for Huffman only compression as in "wb1h", or 'R' for run-length encoding as in "wb1R". (See the description of deflateInit2 for more information about the strategy parameter.) gzopen can be used to read a file which is not in gzip format; in this case gzread will directly read from the file without decompression. gzopen returns NULL if the file could not be opened or if there was insufficient memory to allocate the (de)compression state; errno can be checked to distinguish the two cases (if errno is zero, the zlib error is Z_MEM_ERROR). */ |
ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); ZEXTERN int ZEXPORT gzwrite OF((gzFile file, voidpc buf, unsigned len)); ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, z_off_t offset, int whence)); ZEXTERN int ZEXPORT gzclose OF((gzFile file)); …… |
#include >zlib.h< /* 因为 gz 相关的函数在这个头文件中定义的 */ #include >zconf.h< #include >stdio.h< /* 因为 printf 相关的函数在这个头文件中定义的 */ #include >errno.h< /* 因为 errno 相关的函数在这个头文件中定义的 */ #include >stdlib.h< /* 因为 exit 函数在这个头文件中定义的 */ #include >string.h< /* 因为 strlen 函数在这个头文件中定义的 */ int main(int argc, char **argv) { gzFile mygzfp; mygzfp = gzopen(argv[1], "w"); if(mygzfp == NULL) { printf("以写方式打开文件'%s'出错,错误信息:%s", argv[1], strerror(errno)); exit(0); } gzwrite(mygzfp, argv[2], strlen(argv[2])); gzclose(mygzfp); return 0; } />/>/>/>/>/> |
【作者: Liberal】【访问统计:】【2007年10月26日 星期五 19:02】【注册】【打印】