如何解决未定义的参考膨胀/放气功能? [英] How to fix undefined references to inflate/deflate functions?
本文介绍了如何解决未定义的参考膨胀/放气功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图通过 zlib
来提供示例中提供的现有代码,但它本身给了我错误:
nikhil @ nikhil-Vostro-3500:〜/ zlib-1.2.8 / examples $ gcc -o zpipe -g zpipe.c
/ tmp / ccVZzqsb .o:在函数`def'中:
/home/nikhil/zlib-1.2.8/examples/zpipe.c:32:对`deflateInit_'的未定义引用
/home/nikhil/zlib-1.2 .8 / examples / zpipe.c:40:对`deflateEnd'的未定义引用
/home/nikhil/zlib-1.2.8/examples/zpipe.c:51:对`deflate'的未定义引用
/home/nikhil/zlib-1.2.8/examples/zpipe.c:55:对'deflateEnd'的未定义引用
/home/nikhil/zlib-1.2.8/examples/zpipe.c:66:未定义参考到`deflateEnd'
/tmp/ccVZzqsb.o:在函数`inf'中:
/home/nikhil/zlib-1.2.8/examples/zpipe.c:90:对'inflateInit_'的未定义引用
/home/nikhil/zlib-1.2.8/examples/zpipe.c:98:对'inflateEnd'的未定义引用
/home/nikhil/zlib-1.2.8/examples/zpipe.c: 109:未定义引用'inflate'
/home/nikhil/zlib-1.2.8/examples/zpipe.c:116:对'inflateEnd'的未定义引用
/home/nikhil/zlib-1.2.8/examples /zpipe.c:121:对'inflateEnd'的未定义引用
/home/nikhil/zlib-1.2.8/examples/zpipe.c:130:对'inflateEnd'的未定义引用
collect2:错误: ld返回1退出状态
nikhil @ nikhil-Vostro-3500:〜/ zlib-1.2.8 / examples $
如何正确编译文件? 解决方案
您遇到链接器错误, t告诉编译器链接包含您使用的函数的库。编译在 Ubuntu 上使用 zlib
的简单程序的常用方式为:
gcc -o foo foo.c -lz
I am trying to compile existing code provided in examples by zlib
, but it is giving me error at the first place itself:
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$
How can I compile the file correctly?
解决方案
You're getting a linker error because you haven't told the compiler to link the library that contains the functions that you've used. The usual way of compiling a simple program that uses zlib
on Ubuntu would be:
gcc -o foo foo.c -lz
这篇关于如何解决未定义的参考膨胀/放气功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文