从标题开始,编译时
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <dirent.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <dirent.h>
#include <errno.h>
#include <math.h>
#include <pthread.h>
#include <assert.h>
#include <zlib.h>
int main(){
char *infilename = "triples.txt.gz";
char *outfilename = "out_test.txt";
gzFile infile = gzopen(infilename, "rb");
FILE *outfile = fopen(outfilename, "wb");
if (!infile || !outfile) return -1;
char buffer[128];
int num_read = 0;
num_read = gzread(infile, buffer, sizeof(buffer));
while (num_read > 0) {
fwrite(buffer, 1, num_read, outfile);
}
gzclose(infile);
fclose(outfile);
return 0;
}
我收到消息了
Undefined symbols for architecture x86_64:
"_gzclose", referenced from:
_main in ccfPmLqz.o
"_gzopen", referenced from:
_main in ccfPmLqz.o
"_gzread", referenced from:
_main in ccfPmLqz.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
我搞不清它在说什么。zlib似乎是在调整代码时安装的,因为我对特定的zlib函数有一些错误(比如gzopen没有足够的参数)。
最佳答案
编译时没有链接zlib。假设zlib位于标准路径中,则需要编译为
gcc -lz -o c_test sometest.c
关于c - zlib函数找不到符号,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58544591/