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
unsigned long sourcelen;
unsigned long buflen;
char *compression(char *s)
{
//压缩之后的数据
unsigned char achComp[strlen(s)];
unsigned long nCompLen = 0 ;
patoca(s,(char*)&achComp);
nCompLen=sizeof(achComp);
//解压缩之后的数据
unsigned char achUncomp[nCompLen];
unsigned long nUncompLen = nCompLen;
compress(achUncomp,&nUncompLen,achComp,nCompLen);
char* p = (char*)achUncomp;
return p;
}
char *uncompression(char *buf)
{
//压缩之后的数据
unsigned char achComp[1024];
unsigned long nCompLen = 0 ;
patoca(buf,(char*)&achComp);
nCompLen=sizeof(achComp);
//解压缩之后的数据
unsigned char achUncomp[nCompLen*10];
unsigned long nUncompLen = nCompLen*10 ;
uncompress(achUncomp,&nUncompLen, achComp,nCompLen);
char* p = (char*)achUncomp;
return p;
}
复制代码
这是从网上弄来的两个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
find /usr -name zlib.so
/usr/lib/ruby/1.9.1/i686-linux/zlib.so
/usr/lib/python2.7/lib-dynload/zlib.so
/usr/lib/imlib2/loaders/zlib.so
复制代码
这是我查找到的,要怎么处理呢?
作者:
liwangli1983
时间:
2013-02-15 16:04
因为-lxxx只对libxxx这种命名的库起作用,所以你这里直接跟上zlib.so就好
作者:
jd808
时间:
2013-02-15 16:59
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