【问题标题】:How to fix undefined references to inflate/deflate functions?如何修复对充气/放气函数的未定义引用?
【发布时间】:2014-03-11 22:19:32
【问题描述】:

我正在尝试编译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$ 

如何正确编译文件?

【问题讨论】:

  • 你需要告诉编译器在你的命令行中链接zlib。查看man gcc 中的-l-L 标志
  • 或者可能只是在那个示例目录中运行'make'。 zlib1g 和 zlib1g-dev 是给你 zlib 的 Ubuntu 软件包。
  • 如果它找到了zlib.h,它似乎是,假设zlib1g-dev已安装是合理的。
  • @Emmet 谢谢。从 pecl 或源安装 grpc 时,这一点很清楚,并且有助于解决其他问题,例如“zlib.h:没有这样的文件或目录”:github.com/grpc/grpc/issues/12597

标签: c ubuntu gcc compilation zlib


【解决方案1】:

您收到链接器错误,因为您没有告诉编译器链接包含您使用过的函数的库。在 Ubuntu 上编译使用 zlib 的简单程序的常用方法是:

gcc -o foo foo.c -lz

【讨论】:

  • 澄清一下,参考文件不在 tmp. gcc 作为编译阶段创建的临时目标文件位于 /tmp 中。这是一个链接器错误。
猜你喜欢
  • 2021-12-09
  • 1970-01-01
  • 2020-07-10
  • 2010-12-10
  • 2022-01-14
  • 2016-07-05
  • 1970-01-01
  • 1970-01-01
  • 2022-06-10
相关资源
最近更新 更多