【发布时间】: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