I'm working on compiling OpenSSH for Android based on this answer at Stack Overflow.
Here's what I've done so far:
- Building on Ubuntu 14.04 amd64.
apt-get install build-essential gcc-arm-linux-androideabi
Download zlib, then do:
cd zlib-1.2.8
./configure --prefix=/vagrant/build
make CC=arm-linux-androideabi-gcc
make install
This fails at the make
step:
gcc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -o libz.so.1.2.8 adler32.lo crc32.lo deflate.lo infback.lo inffast.lo inflate.lo inftrees.lo trees.lo zutil.lo compress.lo uncompr.lo gzclose.lo gzlib.lo gzread.lo gzwrite.lo -lc
/usr/bin/ld: crc32.lo: Relocations in generic ELF (EM: 40)
crc32.lo: error adding symbols: File in wrong format
collect2: error: ld returned 1 exit status
make: *** [libz.so.1.2.8] Error 1
What am I missing here? Is there something else it needs to know about to be able to build zlib?
Next in the process is to build OpenSSL:
cd openssl-1.0.1h/
./Configure dist --prefix=/vagrant/build/
make CC="arm-linux-androideabi-gcc" AR="arm-linux-androideabi-ar r" RANLIB="arm-linux-androideabi-ranlib"
make install
This again fails at the make
step:
make[2]: Entering directory `/vagrant/openssl-1.0.1h/apps'
( :; LIBDEPS="${LIBDEPS:--L.. -lssl -L.. -lcrypto }"; LDCMD="${LDCMD:-cc}"; LDFLAGS="${LDFLAGS:--O}"; LIBPATH=`for x in $LIBDEPS; do echo $x; done | sed -e 's/^ *-L//;t' -e d | uniq`; LIBPATH=`echo $LIBPATH | sed -e 's/ /:/g'`; LD_LIBRARY_PATH=$LIBPATH:$LD_LIBRARY_PATH ${LDCMD} ${LDFLAGS} -o ${APPNAME:=openssl} openssl.o verify.o asn1pars.o req.o dgst.o dh.o dhparam.o enc.o passwd.o gendh.o errstr.o ca.o pkcs7.o crl2p7.o crl.o rsa.o rsautl.o dsa.o dsaparam.o ec.o ecparam.o x509.o genrsa.o gendsa.o genpkey.o s_server.o s_client.o speed.o s_time.o apps.o s_cb.o s_socket.o app_rand.o version.o sess_id.o ciphers.o nseq.o pkcs12.o pkcs8.o pkey.o pkeyparam.o pkeyutl.o spkac.o smime.o cms.o rand.o engine.o ocsp.o prime.o ts.o srp.o ${LIBDEPS} )
/usr/bin/ld: openssl.o: Relocations in generic ELF (EM: 40)
/usr/bin/ld: openssl.o: Relocations in generic ELF (EM: 40)
openssl.o: error adding symbols: File in wrong format
collect2: error: ld returned 1 exit status
make[2]: *** [link_app.] Error 1
make[2]: Leaving directory `/vagrant/openssl-1.0.1h/apps'
make[1]: *** [openssl] Error 2
make[1]: Leaving directory `/vagrant/openssl-1.0.1h/apps'
make: *** [build_apps] Error 1
Again it seems to be having the same problem, not being able to read a file that it wrote.
I haven't made it to the final step of compiling OpenSSH yet, but this is how I assume that I'd do it:
cd openssh-6.6p1
./configure --host=arm-linux --with-libs --with-zlib=$HOME/zlibArm --with-ssl-dir=$HOME/opensslArm --disable-etc-default-login CC=gcc-arm-linux-gnueabi-gcc AR=gcc-arm-linux-gnueabi-ar
make
Why is my compilation above failing for Zlib and OpenSSL when compiling for arm-linux-androideabi
? How can I compile OpenSSH (specifically the client and the agent) for Android on ARM?
Best Answer
The reason your builds are failing is because Make is using your platform's linker(/usr/bin/ld) to link the object files that arm-linux-androideabi-gcc produces. You need to tell configure to look for the correct tools, then try compiling again. You should also have Android NDK installed somewhere, and point NDK_ROOT to that location. Here is a small script I use to get programs to compile for an android target.
I realize this is a rather late response, but hopefully this helps someone anyway.