Coder Perfect

“/usr/bin/ld: unable to locate -lz”

Problem

Under Ubuntu 10.04, I’m attempting to compile Android source code. I get an error message that says,

Could you please tell me how I can resolve this? What does -lz indicate when it says “cannot find”? The complete error message is as follows:

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 here’s what my GCC version produced:

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.

The zlib1g-dev library is already installed:

$ 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 learned this from this website.)

Asked by michael

Solution #1

I had the same problem as you, and adding zlib1g-dev did not help. I was able to get over issue by installing lib32z1-dev. I have a 64-bit system, however it appears that the 32-bit DLL was required.

Answered by kylefinn

Solution #2

Install zlib1g-dev for x64.

sudo apt-get install zlib1g-dev

I don’t require all of the x86 libraries;)

Answered by phedoreanu

Solution #3

In Ubuntu, use sudo apt-get install libz-dev.

Answered by Siva mbigai M

Solution #4

I just ran into this issue, and contrary to the commonly recognized solutions of “your make files are faulty” and “host includes should never be used in a cross compilation,” I came up with my own solution.

Many host executables utilized by the SDK to develop an android app are included in the android build. Make stopped constructing zipalign in my case, which is needed to optimize an apk before installing it on an Android device.

My problem was solved by installing lib32z1-dev, which you can do with the following line on Ubuntu:

sudo apt-get install lib32z1-dev

Answered by Adam

Solution #5

I had the same problem, but installing zlib-devel fixed it. Type the command and install the zlib package.

On linux:

sudo apt-get install zlib*

On Centos:

sudo yum install zlib*

Answered by Abhi km

Post is based on https://stackoverflow.com/questions/3373995/usr-bin-ld-cannot-find-lz