如何修复 /usr/bin/ld: cannot find -lzlib

问题:

你想编译使用 zlib 的 C++ 可执行文件,但你看到类似这样的错误消息

output.txt
/usr/bin/ld: cannot find -lzlib
collect2: error: ld returned 1 exit status

解决方案

使用 -lz 而不是 -lzlib。zlib 库命名为 libz.so,而不是 libzlib.so

示例:

build.sh
g++ -o ztest zpipe.c -lz

Check out similar posts by category: C/C++