Linux “/usr/bin/ld:找不到-lz”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3373995/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 20:19:52  来源:igfitidea点击:

"/usr/bin/ld: cannot find -lz"

linuxgcclinker

提问by michael

I am trying to compile Android source code under Ubuntu 10.04. I get an error saying,

我正在尝试在 Ubuntu 10.04 下编译 Android 源代码。我收到一个错误说,

/usr/bin/ld: cannot find -lz

/usr/bin/ld: 找不到 -lz

Can you please tell me how can I fix it? What does cannot find -lzmean? Here's the full error message:

你能告诉我我该如何解决吗?什么cannot find -lz意思?这是完整的错误消息:

external/qemu/Makefile.android:1101: warning: overriding commands for target `external/qemu/android/avd/hw-config-defs.h'
external/qemu/Makefile.android:933: warning: ignoring old commands for target `external/qemu/android/avd/hw-config-defs.h'
host SharedLib: libneo_cgi (out/host/linux-x86/obj/lib/libneo_cgi.so)
/usr/bin/ld: skipping incompatible /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../libz.so when searching for -lz
/usr/bin/ld: skipping incompatible /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../libz.a when searching for -lz
/usr/bin/ld: skipping incompatible /usr/lib/libz.so when searching for -lz
/usr/bin/ld: skipping incompatible /usr/lib/libz.a when searching for -lz
/usr/bin/ld: cannot find -lz
collect2: ld returned 1 exit status
make: *** [out/host/linux-x86/obj/lib/libneo_cgi.so] Error 1

And my GCC version output:

我的 GCC 版本输出:

scheung@scheung-virtual-box:/media/EXTDIV/mydroid$ gcc --version
gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

I already have the zlib1g-devlibrary installed:

我已经安装了zlib1g-dev库:

$ sudo apt-get install zlib1g-dev 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
zlib1g-dev is already the newest version.

(I get that from this link.)

(我是从这个链接得到的。)

回答by Jonathan Leffler

It means you asked it to include the library 'libz.a' or 'libz.so' containing a compression package, and although the compiler found some files, none of them was suitable for the build you are using.

这意味着您要求它包含包含压缩包的库“libz.a”或“libz.so”,尽管编译器找到了一些文件,但它们都不适合您正在使用的构建。

You either need to change your build parameters or you need to get the correct library installed or you need to specify where the correct library is on the link command line with a -L/where/it/is/libtype option.

您要么需要更改构建参数,要么需要安装正确的库,或者需要使用-L/where/it/is/lib类型选项在链接命令行上指定正确库的位置。

回答by kylefinn

I had the exact same error, and like you, installing zlib1g-dev did not fix it. Installing lib32z1-dev got me past it. I have a 64 bit system and it seems like it wanted the 32 bit library.

我有完全相同的错误,和你一样,安装 zlib1g-dev 并没有修复它。安装 lib32z1-dev 让我过去了。我有一个 64 位系统,它似乎想要 32 位库。

回答by Adam

I just encountered this problem and contrary to the accepted solution of "your make files are broken" and "host includes should never be included in a cross compile"

我刚刚遇到了这个问题,并且与公认的“您的 make 文件已损坏”和“主机包含不应包含在交叉编译中”的解决方案相反

The android build includes many host executables used by the SDK to build an android app. In my case the make stopped while building zipalign, which is used to optimize an apk before installing on an android device.

android 构建包括许多主机可执行文件,SDK 使用它们来构建 android 应用程序。在我的情况下,make 在构建 zipalign 时停止,它用于在安装到 android 设备之前优化 apk。

Installing lib32z1-dev solved my problem, under Ubuntu you can install it with the following command:

安装 lib32z1-dev 解决了我的问题,在 Ubuntu 下你可以使用以下命令安装它:

sudo apt-get install lib32z1-dev

回答by Conley Owens

Others have mentioned that lib32z-dev solves the problem, but in general the required packages can be found here:

其他人提到 lib32z-dev 解决了这个问题,但通常可以在这里找到所需的包:

http://source.android.com/source/initializing.htmlSee "Installing required packages"

http://source.android.com/source/initializing.html请参阅“安装所需的包”

回答by qneill

This will show you clues about why the linker doesn't want the installed library:

这将向您显示链接器为什么不想要安装的库的线索:

LD_DEBUG=all make ...

I had the same problem in a different context: my system /lib/libz.so.1 had unsatisfied dependencies on libc because I was trying to relink on a different version of the OS.

我在不同的上下文中遇到了同样的问题:我的系统 /lib/libz.so.1 对 libc 的依赖不令人满意,因为我试图在不同版本的操作系统上重新链接。

回答by euthygenes

for opensuse 12.3 (Dartmouth) (i586) sudo zypper install zlib-devel zlib-devel-static

对于 opensuse 12.3 (Dartmouth) (i586) sudo zypper install zlib-devel zlib-devel-static

回答by jhclark

Another possible cause: You've passed --static to the linker, but you only have a dynamic version of libz (libz.so), but not a version that can be statically linked (libz.a).

另一个可能的原因:您已将 --static 传递给链接器,但您只有动态版本的 libz (libz.so),但没有可以静态链接的版本 (libz.a)。

回答by phedoreanu

For x64 just install zlib1g-dev.

对于 x64,只需安装 zlib1g-dev。

sudo apt-get install zlib1g-dev

I don't need all the x86 libs ;)

我不需要所有的 x86 库;)

回答by Siva mbigai M

sudo apt-get install libz-devin ubuntu.

sudo apt-get install libz-dev在 ubuntu 中。

回答by Abhi km

I had the exact same error, Installing zlib-devel solved my problem, Type the command and install zlib package.

我遇到了完全相同的错误,安装 zlib-devel 解决了我的问题,键入命令并安装 zlib 包。

On linux:

在 Linux 上:

sudo apt-get install zlib*

On Centos:

在 Centos 上:

sudo yum install zlib*