-1
我想学习zlib模块,但是当我编译我的代码时,它总是说zlib提供的所有函数名都没有定义。这里是我的代码,任何帮助表示感谢,谢谢。C zlib链接错误
#include <stdio.h>
#include <zlib.h>
int compressFile(char *infilename, char *outfilename){
//Opens the needed files
FILE * infile = fopen(infilename, "rb");
gzFile outfile = gzopen(outfilename, "wb");
//Checks if the files are correctly opened
if (!infile || !outfile) return -1;
char inbuffer[128];
int numRead = 0;
while ((numRead = fread(inbuffer, 1, sizeof(inbuffer), infile)) > 0){
gzwrite(outfile, inbuffer, numRead);
}
fclose(infile);
gzclose(outfile);
}
以下是错误
cc test.c -o test
test.c: In function ‘main’:
test.c:24:2: warning: implicit declaration of function ‘comressFile’ [-Wimplicit-function-declaration]
comressFile("hello.txt", "hello.zip");
^
/tmp/cc32e8i4.o: In function `compressFile':
test.c:(.text+0x41): undefined reference to `gzopen'
test.c:(.text+0x7c): undefined reference to `gzwrite'
test.c:(.text+0xbd): undefined reference to `gzclose'
/tmp/cc32e8i4.o: In function `main':
test.c:(.text+0xd7): undefined reference to `comressFile'
collect2: error: ld returned 1 exit status
<builtin>: recipe for target 'test' failed
make: *** [test] Error 1