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

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.)

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.

For x64 install zlib1g-dev.
sudo apt-get install zlib1g-dev
I don't need all the x86 libs ;)

sudo apt-get install libz-dev in ubuntu.

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

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*

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).

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-devlib for ex to get it.
For rhel7 like systems the package is zlib-devel

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.

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.

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

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"

Related

How to fix 'Unable to locate package' error in apt-cyg

Im using Cygwin and I need to install a g++ compiler, so I tried with apt-cyg.
It returns an error that happens with some packages but not with others. For instance, I could install git package, which I found in blogs that talk about this topic to try it as an example. However, when trying g++:
$ apt-cyg install g++
Installing g++
Unable to locate package g++
What is going on?
First, I would suggest you use the standard Cygwin setup-x86_64.exe (or its 32-bit version if appropriate) rather than apt-cyg. Scanning the "Devel" category in setup, you will see a package gcc-g++, which is what you want.
The answer from #varro is correct. However, if you wish to use apt-cyg, you should take advantage of it's search capabilities.
apt-cyg search g++
returns gcc-g++.
Thus, you can execute the following apt-cyg command to install g++:
apt-cyg install gcc-g++

Installing g++ on windows subsystem for linux

A while back I activated Windows Subsystem for Linux on my machine but didn't use it much. Now I have an idea what I could use it for and that is why I'm trying to install gcc/++ 7 on my WSL and keep running into problems.
My idea was to download it and compile it by hand following this guide with:
../gcc/configure -v --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --prefix=${HOME}/software/gcc-7.3.0/installDir --enable-checking=release --enable-languages=c,c++,fortran --disable-multilib
This led to the following error:
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking LIBRARY_PATH variable... ok
checking GCC_EXEC_PREFIX variable... ok
checking whether to place generated files in the source directory... no
checking whether a default linker was specified... no
checking whether a default assembler was specified... no
checking for x86_64-linux-gnu-gcc... no
checking for gcc... no
checking for x86_64-linux-gnu-cc... no
checking for cc... no
checking for x86_64-linux-gnu-cl.exe... no
checking for cl.exe... no
configure: error: in `$HOME/software/gcc-7.3.0/build':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details.
Apparently, there was no(?) gcc installed at all. At least gcc and cc yielded "command not found". So my next step was installing gcc via:
sudo apt install gcc
This worked:
$ gcc --version
gcc (Ubuntu 4.8.4-2ubuntu1~14.04.4) 4.8.4
Copyright (C) 2013 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.
However when trying the configure command from above I got:
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking LIBRARY_PATH variable... ok
checking GCC_EXEC_PREFIX variable... ok
checking whether to place generated files in the source directory... no
checking whether a default linker was specified... no
checking whether a default assembler was specified... no
checking for x86_64-linux-gnu-gcc... x86_64-linux-gnu-gcc
checking for C compiler default output file name...
configure: error: in `/home/seriously-ubuntu/software/gcc-7.3.0/build':
configure: error: C compiler cannot create executables
see `config.log' for more details.
So I tried to compile a simple c program by hand:
int main() {
return 42;
}
Which hints that something seems to be seriously broken
$ gcc foo.c
/usr/bin/ld: cannot find crt1.o: No such file or directory
/usr/bin/ld: cannot find crti.o: No such file or directory
/usr/bin/ld: cannot find -lc
/usr/bin/ld: cannot find crtn.o: No such file or directory
collect2: error: ld returned 1 exit status
Any Ideas where I can even start to repair this? I wouldn't even mind reseting the whole WSL if this helps :/
lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.3 LTS
Release: 16.04
Codename: xenial
UPDATE:
Before all of this I tried installing gcc7 / g++/ via apt without success:
$ sudo add-apt-repository ppa:jonathonf/gcc-7.1
$ sudo apt-get update
$ sudo apt-get install gcc-7 g++-7
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
g++-7 : Depends: libstdc++-7-dev (= 7.1.0-10ubuntu1~16.04.york0) but it is not going to be installed
Depends: libisl15 (>= 0.15) but it is not installable
gcc-7 : Depends: cpp-7 (= 7.1.0-10ubuntu1~16.04.york0) but it is not going to be installed
Depends: binutils (>= 2.26.1) but 2.24-5ubuntu14.2 is to be installed
Depends: libisl15 (>= 0.15) but it is not installable
Recommends: libc6-dev (>= 2.13-0ubuntu6) but it is not going to be installed
E: Unable to correct problems, you have held broken packages
UPDATE 2
Sadly none of the suggested ways helped and I ended up nuking the WSL. Apparently, something more severe was broken.
Why compiling? You should be able to install the package:
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt update
sudo apt install g++-7 -y
Verify using:
gcc-7 --version
See How to install gcc-7 or clang 4.0?
run the following
sudo apt install aptitude
sudo aptitude install gcc-7 g++-7
or
sudo apt install aptitude && sudo aptitude install golang gcc-7 g++-7
crt1.o is generally provided as part of the libdevc dependency (or something similar). I would suggest running sudo apt search libc or some similar variant with lib6c, libdev, libc-dev etc. Installing those fixed a similar issue I had recently.
Failing that, run find / -iname ctri.o and add the folder it appears in to your PATH with export PATH="[folder]:$PATH", and see if that helps.
As you can see here, g++ is just a package in the default ubuntu package repository (for ubuntu 18.04, 20.04 and 22.04 and others).
So it's actually enough to just run this.
sudo apt update
sudo apt install g++
Afterwards you can check with:
g++ --version
which resulted in version 9.4.0 at the time of writing.
However, you can also pick a specific version (e.g. apt install g++-12). However then the binary will also have a specific name (e.g. g++-12) and you may need to add a symlink if you need it to be g++. (e.g. ln -s /usr/bin/g++-12 /usr/bin/g++).

How to install Petite Chez Scheme on Ubuntu?

How to install Petite Chez Scheme on Ubuntu?
I run Ubuntu 15.10 and try to install pcsv8.4-a6le.tar.gz (non-threaded, 64 bit) for Linux.
After having unpacked this tar in /usr/locale, I enter the commands
sudo ./configure
sudo make install
from within the custom directory.
However, instead of a clean install, I get the following errors (which I hope someone can help me out with):
nlykkei#nlykkei-Studio-XPS-1640:/usr/local/csv8.4/custom$ sudo make install
if [ yes = no ]; then if [ ! -f ./scheme ]; then /bin/rm -f ./scheme; ln -s ../bin/a6le/scheme ./scheme; fi; fi
if [ ! -f ./petite ]; then /bin/rm -f ./petite; ln -s ./scheme ./petite; fi
/bin/rm -f ./scheme
echo "const char *S_date_stamp = \"`date +%m%d%Y%H%M%S`\";" > datestamp.c
gcc -m64 -rdynamic -o ./scheme datestamp.c ../boot/a6le/kernel.o ../boot/a6le/custom.o -lm -ldl -lncurses -lrt
/usr/bin/ld: cannot find -lncurses
collect2: error: ld returned 1 exit status
Mf-a6le:22: recipe for target 'scheme' failed
make[2]: *** [scheme] Error 1
Makefile:47: recipe for target 'buildpetite' failed
make[1]: *** [buildpetite] Error 2
Mf-install:64: recipe for target 'install' failed
make: *** [install] Error 2
On recent versions of Ubuntu (and future versions of Debian e.g. "Buster", and other Debian based distros), you can install Chez Scheme directly from the repo(s) by:
sudo apt install chezscheme
Previously you had to install it by compiling from source. Chez Scheme has been open source, for a few years now, and can be compiled from source, if it is not directly installable from the distribution's repo(s). Just download the source code compile and install. This will install not just the "petite" runtime version but also the full compiler. You can compile and install the software with:
./configure
sudo make install
Full build and install instructions are available here.
Pre-requisites for building are:
GNU Make
GCC
Header files and libraries for ncurses
Header files and libraries for X windows
On Ubuntu, install the libncurses5-dev package to get libncurses.so. (You can discover this by visiting http://packages.debian.org/file:libncurses.so (sadly, this doesn't seem to work for http://packages.ubuntu.com/file:libncurses.so).)
You may find other linkage errors if Chez requires other libraries to have development packages installed too. Use the same technique as above.
Go directly building from their Github.
ChezScheme
And then just do
./configure
sudo make install
Prerequisites according to Building are:
GNU Make
gcc
Header files and libraries for ncurses
Header files and libraries for X windows
And yes in case On Ubuntu, install the libncurses5-dev as Chris stated. Did just that and have no errors shown in clean install.
Chez Scheme has been open sourced since this question was asked. Since Bionic (18.04LTS) the full chezscheme is available as a repository.
First do
sudo apt update
then install the package:
sudo apt install chezscheme
This provides both the petite interpreter and the full scheme compiler.
There is also a PPA for trusty and xenial here:
https://launchpad.net/~jonathonf/+archive/ubuntu/lisp?field.series_filter=
Download the RPM package instead and use alien from terminal to produce a deb file:
fakeroot alien PetiteChezScheme-8.4-1.x86_64.rpm
You may need to install fakeroot, alien for this to work:
apt-get install fakeroot alien
Then you'll have a deb file. If you are on a desktop you can just double click the file and it will open Software Center and you can click install and it will fix your dependency problems.

How to use g++-3.4 in ubuntu 15.04

I want to use g++3.4 in ubuntu 15.04, but I have trouble doing it for a week.
I followed the answer to install g++3.4.
https://askubuntu.com/questions/39628/old-version-of-gcc-for-new-ubuntu
And I chose g++-3.4 with the method provided on
https://askubuntu.com/questions/26498/choose-gcc-and-g-version
When I want to compile a cpp file, an error display:
/usr/bin/ld: cannot find -lgcc_s.
So I searched a lot of information about the problem, I find the following:
http://serverfault.com/questions/266138/cannot-find-lgcc-s-from-gcc-3-4-on-ubuntu-11-04
Because I don't have i486-linux-gnu directory, I typed
sudo ln /lib/i386-linux-gnu/libgcc_s.so.1 /usr/lib/gcc/x86_64-linux-gnu/3.4.6/libgcc_s.so
But the terminal displayed the error:
ln: failed to create hard link ‘/usr/lib/gcc/x86_64-linux-gnu/3.4.6/libgcc_s.so’: File exists
then I type the command
sudo cp /lib/i386-linux-gnu/libgcc_s.so.1 /lib/libgcc_s.so.1
It seemed to work. But when I compiled again, the terminal showed that
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/3.4.6/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/3.4.6/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
Afterward I thought that it was because I didn't have 32-bit support. But I couldn't download ia32-libs package. It seems that the package don't exist on latest ubuntu.
Now I have installed gcc-multilib,lib32gcc1 and libgl1-mesa-dri:i386, and I also have tried the command:
sudo dpkg --add-architecture i386 && sudo apt-get update && sudo apt-get install ia32-libs
I still don't have 32bit support. What should I do?
Not sure you need a 32bits compiler ? Anyway, none of the older compilers, gcc versions 4.3 and lower can be used with Ubuntu 11.10 ... 15.10 .
The information in "askubuntu" etc. is wrong.
The usable version of gcc/g++-3.4.6 is { compat-gcc34-3.4.6-ubuntu1204-1_amd64.deb, compat-gcc-34-c++_3.4.6-20_amd64.deb }
Links for the "amd64 packages" :
compat-gcc34 https://drive.google.com/file/d/0B7S255p3kFXNRTkzQnRSNXZ6UVU/view?usp=sharing
compat-g++34 https://drive.google.com/file/d/0B7S255p3kFXNV3J3bnVoWGNWdG8/view?usp=sharing
.... provides /usr/bin/{ gcc34, g++34 }.
compat-gcc34

How to install `build-essential` in `Cygwin`?

How to install build-essential in Cygwin?
I've tried using: apt-cyg install build-essential
But does not work.
Installing build-essential
Package build-essential not found or ambiguous name, exiting
I'm also having problems like:
(gedit: 13864): Gtk-WARNING **: can not open display:
So I can not install crunch.
See It:
$ make all
Building binary...
/usr/bin/gcc -pthread -Wall -pedantic -std=c99 undefined crunch.c -lm -o crunch
gcc: error: undefined: No such file or directory
Makefile:48: recipe for target 'crunch' failed
make: *** [crunch] Error 1
What's the problem here, and how can I fix it?
There isn't a build-essential package in Cygwin.
Build-essential is a collection of packages. So you'll have to select the packages manually, which I believe are the following:
make
automake
gcc
gcc-c++
Assuming you're doing development, you'll want to select those packages from the Devel branch. This is done when you first install Cygwin and the installer asks you to select the packages, after choosing the download site from the list.
As for the Gtk-WARNING **: can not open display: error, this is because your system is not running Cygwin's X11 display server, which provides a surface for graphical applications to render to. Check out http://x.cygwin.com/.
If you want to run gedit in Windows, you should get the binary for windows here. That's built for Windows and doesn't need Cygwin.
EDIT: Running sudo apt-get install build-essential on Elementary OS Freya mentions the following dependencies will be installed as well, so you'll probably want that for a 'closer-to-Linux' build environment as well.
The following extra packages will be installed:
g++
g++-4.8
libstdc++-4.8-dev
Suggested packages:
g++-multilib
g++-4.8-multilib
gcc-4.8-doc
libstdc++6-4.8-dbg
libstdc++-4.8-doc
The following NEW packages will be installed:
build-essential
g++
g++-4.8
libstdc++-4.8-dev
The list of files installed can be found here
and the contents of the file list (current as of 4/24/2014) can be found in this PasteBin I made.
build-essential is an abstract package, short for its dependencies:
dpkg-dev
binutils
bzip2
libdpkg-perl
make
patch
perl
tar
xz-utils
g++
gcc
libc6-dev
make
So in Cygwin, it is the same to install their substitutes:
apt-cyg install make gcc-core gcc-g++ patch bzip2 perl tar xz
make and gcc-g++ (g++), which depends on gcc-core (gcc), are the most important.
If you really want to compile various projects in Cygwin, packages below may be also helpful. Be careful, libboost-devel is very large.
apt-cyg install git automake cmake python3-devel libboost-devel

Resources