-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