为什么加了zlib库 还是提示compress()未定义
代码:
// testzlib.cpp 简单测试 zlib 的压缩功能
#include<stdio.h>
#include<zlib.h>
#include<string.h>
#include<stdlib.h>
int main()
{
int err;
Byte compr[200], uncompr[200]; // big enough
uLong comprLen, uncomprLen;
const char* hello = "12345678901234567890123456789012345678901234567890";
uLong len = strlen(hello) + 1;
comprLen = sizeof(compr) / sizeof(compr[0]);
err =compress(compr, &comprLen, (const Bytef*)hello, len);
if (err != Z_OK) {
//cerr << "compess error: " << err << '\n';
printf("error:compress error!\n");
exit(1);
}
//cout << "orignal size: " << len<< " , compressed size : " << comprLen << '\n';
printf("orignal size: %d compressed size: %d \n",len,comprLen);
strcpy((char*)uncompr, "garbage");
err = uncompress(uncompr, &uncomprLen, compr, comprLen);
if (err != Z_OK) {
// cerr << "uncompess error: " << err << '\n';
printf("error:uncompress error!\n");
exit(1);
}
//cout << "orignal size: " << len << " , uncompressed size : " << uncomprLen << '\n';
printf("orignal size:%d uncopressed size :%d \n",len,uncomprLen);
if (strcmp((char*)uncompr, hello)) {
// cerr << "BAD uncompress!!!\n";
printf("error:bad uncompress!");
exit(1);
}
else {
// cout << "uncompress() succeed: \n" << (char *)uncom
printf("uncompress() suceed :%s\n",(char*)uncompr);
}
}
提示错误:
1.c:(.text+0x75): undefined reference to `compress'
1.c:(.text+0xf2): undefined reference to `uncompress'
但是我的/usr/linclude/目录下有zlib库 ,求解啊—。—