c - 如何修复对膨胀/收缩函数的 undefined reference ?

标签 c ubuntu gcc compilation zlib

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

相关文章:

c - 如何从文件中读取文本到数组

c - 在 C 中返回动态分配的结构时出现未处理的异常

python - gcloud SDK 中的 bq 在虚拟环境中不起作用

gcc - glibc-2.15 无法删除 `/var/db/Makefile'

iphone - -all_load 链接器标志有什么作用?

c++ - 如何在不使用命名空间 std 和字符串库的情况下拆分和存储 const char*?

在生产环境中捕捉返回码?

c++ - 如何从 C++ 程序执行命令行命令

php - vagrant-shopware 建立数据库连接失败

python setup.py Egg_info gcc 安装 cassandra python 时出错