Chinaunix

标题: 我引入了zlib.h,编译的时候是否需要加-lzlib?? [打印本页]

作者: jd808    时间: 2013-02-15 13:04
标题: 我引入了zlib.h,编译的时候是否需要加-lzlib??
我引入了
#include <zlib.h>  
是否要加上-lzlib??如下
g++ ./test.cpp -o test -lpthread  -ljson -lzlib

但我加上报错了

/usr/bin/ld: cannot find -lzlib
collect2: ld 返回 1
如果不加上也报错
/tmp/ccQrOjbE.o: In function `compression(char*)':
test.cpp.text+0x5f55): undefined reference to `compress'
/tmp/ccQrOjbE.o: In function `uncompression(char*)':
test.cpp.text+0x6075): undefined reference to `uncompress'
collect2: ld 返回 1
是咋回事??


作者: jd808    时间: 2013-02-15 13:11
  1. unsigned long sourcelen;
  2. unsigned long buflen;
  3. char *compression(char *s)
  4. {
  5.         //压缩之后的数据
  6.         unsigned char achComp[strlen(s)];
  7.         unsigned long nCompLen = 0 ;
  8.         patoca(s,(char*)&achComp);
  9.         nCompLen=sizeof(achComp);

  10.         //解压缩之后的数据
  11.         unsigned char achUncomp[nCompLen];
  12.         unsigned long nUncompLen = nCompLen;
  13.         compress(achUncomp,&nUncompLen,achComp,nCompLen);
  14.         char* p = (char*)achUncomp;
  15.         return p;
  16. }

  17. char *uncompression(char *buf)
  18. {
  19.         //压缩之后的数据
  20.         unsigned char achComp[1024];
  21.         unsigned long nCompLen = 0 ;
  22.         patoca(buf,(char*)&achComp);
  23.         nCompLen=sizeof(achComp);

  24.         //解压缩之后的数据
  25.         unsigned char achUncomp[nCompLen*10];
  26.         unsigned long nUncompLen = nCompLen*10 ;

  27.         uncompress(achUncomp,&nUncompLen, achComp,nCompLen);
  28.         char* p = (char*)achUncomp;
  29.         return p;
  30. }
复制代码
这是从网上弄来的两个zlib对字符串的压缩和解压缩程序,王大侠帮忙看下有何不妥的
作者: folklore    时间: 2013-02-15 13:12
/usr/bin/ld: cannot find -lzlib


you must specify where the zlib.so/.o are. its location is required.
作者: jd808    时间: 2013-02-15 15:29
  1. find /usr -name zlib.so
  2. /usr/lib/ruby/1.9.1/i686-linux/zlib.so
  3. /usr/lib/python2.7/lib-dynload/zlib.so
  4. /usr/lib/imlib2/loaders/zlib.so
复制代码
这是我查找到的,要怎么处理呢?
作者: liwangli1983    时间: 2013-02-15 16:04
因为-lxxx只对libxxx这种命名的库起作用,所以你这里直接跟上zlib.so就好
作者: jd808    时间: 2013-02-15 16:59
  1. g++ ./test.cpp -o test -lpthread  -ljson imlib2/loaders/zlib.so
复制代码
直接这样子?不是很明白,参数要怎么加?
作者: jd808    时间: 2013-02-15 17:16
搞定了,直接-lz就可以了,好奇怪哦
作者: linux_c_py_php    时间: 2013-02-15 18:10
学会看官方文档... 瞎JB折腾没用.




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2