我正在尝试编译 zlib
示例中提供的现有代码,但它本身首先给我错误:
nikhil@nikhil-Vostro-3500:~/zlib-1.2.8/examples$ gcc -o zpipe -g zpipe.c
/tmp/ccVZzqsb.o: In function `def':
/home/nikhil/zlib-1.2.8/examples/zpipe.c:32: undefined reference to `deflateInit_'
/home/nikhil/zlib-1.2.8/examples/zpipe.c:40: undefined reference to `deflateEnd'
/home/nikhil/zlib-1.2.8/examples/zpipe.c:51: undefined reference to `deflate'
/home/nikhil/zlib-1.2.8/examples/zpipe.c:55: undefined reference to `deflateEnd'
/home/nikhil/zlib-1.2.8/examples/zpipe.c:66: undefined reference to `deflateEnd'
/tmp/ccVZzqsb.o: In function `inf':
/home/nikhil/zlib-1.2.8/examples/zpipe.c:90: undefined reference to `inflateInit_'
/home/nikhil/zlib-1.2.8/examples/zpipe.c:98: undefined reference to `inflateEnd'
/home/nikhil/zlib-1.2.8/examples/zpipe.c:109: undefined reference to `inflate'
/home/nikhil/zlib-1.2.8/examples/zpipe.c:116: undefined reference to `inflateEnd'
/home/nikhil/zlib-1.2.8/examples/zpipe.c:121: undefined reference to `inflateEnd'
/home/nikhil/zlib-1.2.8/examples/zpipe.c:130: undefined reference to `inflateEnd'
collect2: error: ld returned 1 exit status
nikhil@nikhil-Vostro-3500:~/zlib-1.2.8/examples$
如何正确编译文件?
最佳答案
您收到链接器错误是因为您没有告诉编译器链接包含您使用的函数的库。在 Ubuntu 上编译使用 zlib
的简单程序的通常方法是:
gcc -o foo foo.c -lz
关于c - 如何修复对膨胀/收缩函数的 undefined reference ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22337896/