"/usr/bin/ld: cannot find -lz"
LinuxGccLinkerLinux Problem Overview
I am trying to compile Android source code under Ubuntu 10.04. I get an error saying,
> /usr/bin/ld: cannot find -lz
Can you please tell me how can I fix it? What does cannot find -lz
mean? Here's the full error message:
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:
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-dev
library 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 get that from this link.)
Linux Solutions
Solution 1 - Linux
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.
Solution 2 - Linux
For x64 install zlib1g-dev
.
sudo apt-get install zlib1g-dev
I don't need all the x86 libs ;)
Solution 3 - Linux
sudo apt-get install libz-dev
in ubuntu.
Solution 4 - Linux
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"
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.
Installing lib32z1-dev solved my problem, under Ubuntu you can install it with the following command:
sudo apt-get install lib32z1-dev
Solution 5 - Linux
I had the exact same error, Installing zlib-devel solved my problem, Type the command and install zlib package.
On linux:
sudo apt-get install zlib*
On Centos:
sudo yum install zlib*
Solution 6 - Linux
Try one of those three solution. It must work :) :
- sudo apt-get install zlib1g-dev
- sudo apt-get install libz-dev
- sudo apt-get install lib32z1-dev
In fact what is missing is not the lz
command, but the development files for the zlib
library.So you should install zlib1g-dev
lib for ex to get it.
For rhel7 like systems the package is zlib-devel
Solution 7 - Linux
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.
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/lib
type option.
Solution 8 - Linux
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).
Solution 9 - Linux
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.
Solution 10 - Linux
for opensuse 12.3 (Dartmouth) (i586) sudo zypper install zlib-devel zlib-devel-static
Solution 11 - Linux
Others have mentioned that lib32z-dev solves the problem, but in general the required packages can be found here:
http://source.android.com/source/initializing.html See "Installing required packages"