2

Followed many tutorials so far and had various error. Below is the complete step by step procedure that i followed and ended up having errors with OpenSSH compilation.

Downloaded Zlib and cross compiled ($HOME/Desktop/Zlib/zlib-1.2.5/output)

cd /home/armsdk/Desktop/
mkdir zlib
cd Zlib
wget http://www.zlib.net/fossils/zlib-1.2.5.tar.gz
tar xzvf zlib-1.2.5.tar.gz
cd zlib-1.2.5
mkdir output
./configure --prefix=/home/armsdk/Desktop/Zlib/zlib-1.2.5/output CC=arm-cortexa9-linux-gnueabi-gcc 
make
make install

Downloaded OpenSSL and cross compiled : ($HOME/Desktop/OpenSSL/OpenSSL_CC)

mkdir OpenSSL
cd OpenSSL
wget http://www.openssl.org/source/openssl-1.0.1g.tar.gz
tar xzvf openssl-1.0.1g.tar.gz      
cd openssl-1.0.1g/
export cross=arm-cortexa9-linux-gnueabi-
./Configure dist --prefix=$HOME/Desktop/OpenSSL/OpenSSL_CC
make CC="${cross}gcc" AR="${cross}ar r" RANLIB="${cross}ranlib"
make install

Cross Compiled OpenSSH :

./configure --prefix=$HOME/Desktop/OpenSSH/OpenSSH_CC --host=arm --with-libs --with-zlib=$HOME/Desktop/Zlib/zlib-1.2.5/output --with-ssl-dir=$HOME/Desktop/OpenSSL/OpenSSL_CC --disable-etc-default-login CC=arm-cortexa9-linux-gnueabi-gcc AR=arm-cortexa9-linux-gnueabi-ar
make

GETTING CRYPT ERROR:

openbsd-compat//libopenbsd-compat.a(xcrypt.o): In function `xcrypt':
/home/armsdk/Desktop/OpenSSH/openssh-5.2p1/openbsd-compat/xcrypt.c:78: undefined reference to `crypt'
collect2: error: ld returned 1 exit status

Please help me resolve. All i need is SFTP-Server for remote debugging using gdbServer (via Eclipse)


Compiling on system running : Debian Wheezy

Target Board : Ka-Ro TX6S

Target Processor : NXP i.MX6S7

Host Linux version : 3.16.0-0.bpo.4-amd64

Target Linux Version : 4.4.0-00118-g26d6b51

CrossCompiler : gcc-arm-cortexa9-linux-gnueabi


Update 1:

Adding the below line Gave error:

-I/home/armsdk/Desktop/OpenSSL/OpenSSL_CC/include

Error

 configure: error: unrecognized option: -I/home/armsdk/Desktop/OpenSSL/OpenSSL_CC/include

Tried this instead but the CRYPT error still exists.

--includedir=/home/armsdk/Desktop/OpenSSL/OpenSSL_CC/include

Update 2:

Tried -lcrypt flag as suggested here : undefined reference to `crypt' But this doesnt have any change in error.

make clean
make -lcrypt

Update 3: Added 'CFLAGS=-lcrypt' and the error now changed

./configure --prefix=$HOME/Desktop/OpenSSH/OpenSSH_CC --host=arm --with-libs --with-zlib=$HOME/Desktop/Zlib/zlib-1.2.5/output --with-ssl-dir=$HOME/Desktop/OpenSSL/OpenSSL_CC --disable-etc-default-login CC=arm-cortexa9-linux-gnueabi-gcc AR=arm-cortexa9-linux-gnueabi-ar CFLAGS=-lcrypt

Error

openbsd-compat//libopenbsd-compat.a(xcrypt.o): In function `xcrypt':
xcrypt.c:(.text+0x2c): undefined reference to `crypt'
collect2: error: ld returned 1 exit status
make: *** [sshd] Error 1

Update 4: Updated the LDFLAGS and CFLAGS as below:

./configure --prefix=$HOME/Desktop/OpenSSH/OpenSSH_CC --host=arm --with-libs --with-zlib=$HOME/Desktop/Zlib/zlib-1.2.5/output --with-ssl-dir=$HOME/Desktop/OpenSSL/OpenSSL_CC --disable-etc-default-login CC=arm-cortexa9-linux-gnueabi-gcc AR=arm-cortexa9-linux-gnueabi-ar LDFLAGS=-L/home/cross-gcc-4.9.1-2.19-18-armv7a-soft/x86_64-pc-linux-gn‌​‌​u/arm-cortexa9-lin‌​ux‌​-gnueabi/sys-roo‌​t/li‌​b CFLAGS=-lcrypt

Issue is still the same:

openbsd-compat//libopenbsd-compat.a(xcrypt.o): In function `xcrypt':
xcrypt.c:(.text+0x2c): undefined reference to `crypt'
collect2: error: ld returned 1 exit status
make: *** [sshd] Error 1

Update 5:

I finally got it to successfully 'MAKE'but not able to 'make install'

./configure --prefix=$HOME/Desktop/OpenSSH/OpenSSH_CC --host=arm --with-libs --with-zlib=$HOME/Desktop/Zlib/zlib-1.2.5/output --with-ssl-dir=$HOME/Desktop/OpenSSL/OpenSSL_CC --disable-etc-default-login CC=arm-cortexa9-linux-gnueabi-gcc AR=arm-cortexa9-linux-gnueabi-ar LDFLAGS='-L/home/cross-gcc-4.9.1-2.19-18-armv7a-soft/x86_64-pc-linux-gn‌​‌​u/arm-cortexa9-lin‌​ux‌​-gnueabi/sys-roo‌​t/li‌​b -lcrypt'

make    
make install

Error when 'make install'

(umask 022 ; ./mkinstalldirs /var/empty)
/usr/bin/install -c -m 0755 -s ssh /home/armsdk/Desktop/OpenSSH/OpenSSH_CC/bin/ssh
strip: Unable to recognise the format of the input file `/home/armsdk/Desktop/OpenSSH/OpenSSH_CC/bin/ssh'
/usr/bin/install: strip process terminated

Update 6 : Hopefully Final

So i finally am able to generate the outputs by adding the flag '--disable-strip'

./configure --prefix=$HOME/Desktop/OpenSSH/OpenSSH_CC --host=arm --disable-strip --with-libs --with-zlib=$HOME/Desktop/Zlib/zlib-1.2.5/output --with-ssl-dir=$HOME/Desktop/OpenSSL/OpenSSL_CC --disable-etc-default-login CC=arm-cortexa9-linux-gnueabi-gcc AR=arm-cortexa9-linux-gnueabi-ar LDFLAGS='-L/home/cross-gcc-4.9.1-2.19-18-armv7a-soft/x86_64-pc-linux-gn‌​‌​u/arm-cortexa9-lin‌​ux‌​-gnueabi/sys-roo‌​t/li‌​b -lcrypt'
make
make install

One small issue though, i had this error :

mkdir /home/armsdk/Desktop/OpenSSH/OpenSSH_CC/etc
./ssh-keygen: 1: ./ssh-keygen: Syntax error: word unexpected (expecting ")")
./ssh-keygen: 1: ./ssh-keygen: Syntax error: word unexpected (expecting ")")
./ssh-keygen: 1: ./ssh-keygen: Syntax error: word unexpected (expecting ")")
make: *** [host-key] Error 2
  • Possible duplicate of [undefined reference to \`crypt'](https://stackoverflow.com/questions/5989444/undefined-reference-to-crypt) – Gaurav Pathak Jul 24 '17 at 09:02
  • After adding the -lcrypt flag to the Compiler Flags, the error now matches with https://stackoverflow.com/questions/5989444/undefined-reference-to-crypt Have no idea what to do now, the above thread's solution was to add the -lcrypt flag. – Feroze Mohamed Jul 24 '17 at 09:44
  • Do you have the libcrypt library for arm in your system? Mine is under /usr/arm-linux-gnueabi/ as well as under x86 folders – k_kaz Jul 24 '17 at 09:45
  • @k_kaz hi, I can find 'libcrypt-2.19.so' and 'libcrypt.so.1' in this path : /home/cross-gcc-4.9.1-2.19-18-armv7a-soft/x86_64-pc-linux-gnu/arm-cortexa9-linux-gnueabi/sys-root/lib/ – Feroze Mohamed Jul 24 '17 at 09:51
  • @FerozeMohamed So please use `-L /home/cross-gcc-4.9.1-2.19-18-armv7a-soft/x86_64-pc-linux-gn‌​u/arm-cortexa9-linux‌​-gnueabi/sys-root/li‌​b/ -lcrypt`. – Gaurav Pathak Jul 24 '17 at 09:54
  • Should not it be `LDFLAGS`? – Jakuje Jul 24 '17 at 10:33
  • @Jakuje did the same and updated the OP with Update 4, still same error. I am obviously missing something here. – Feroze Mohamed Jul 24 '17 at 11:12
  • 1
    I don't see `-lcrypt` in `LDFLAGS` in your example – Jakuje Jul 24 '17 at 11:14
  • @Jakuje I added 'LDFLAGS=-L/home/cross-gcc-4.9.1-2.19-18-armv7a-soft/x86_64-pc-linux-gn‌​‌​u/arm-cortexa9-lin‌​ux‌​-gnueabi/sys-roo‌​t/li‌​b' and 'CFLAGS=-lcrypt' from what i understood, LDFLAGS specify the PATH to libraries and CFLAGS will inform the compiler which library to be used. Please do correct me, I am apparently a newbie. – Feroze Mohamed Jul 24 '17 at 11:32
  • No. CFLAGS specify the flags used for compiling and LDFLAGS are used as flags for linking. – Jakuje Jul 24 '17 at 11:35
  • @Jakuje Ok, so i corrected it to : 'LDFLAGS='-L/home/cross-gcc-4.9.1-2.19-18-armv7a-soft/x86_64-pc-linux-gn‌​‌​u/arm-cortexa9-lin‌​ux‌​-gnueabi/sys-roo‌​t/li‌​b -lcrypt'' and seems to have worked :) Thanks a lot. – Feroze Mohamed Jul 24 '17 at 11:36
  • For Update 4: Hope you can install the header of dependent libraries like glibc zlib etc in target RFS. else you would need to pass as them with CFLAGS & LDFLAGS for headers and libraries. For Update 6 issue: You could make change in Makefile of openssh for STRIP_OPT as STRIP_OPT="--strip-program=arm-linux-gnueabi-strip -s" This needs to be made in Makefile generate with configure. as configure does not has option to pass strip program or its arguments. – Deepak Reddy Apr 18 '21 at 09:57
  • 2
    also update 6 as you are performing cross compile installation. you can use install-nokeys rather than install where it installs with check-config and host-key check-config tries to run sshd with config Also host-key as tries to host rsa/dsa key for target target binary which would fail on host – Deepak Reddy Apr 19 '21 at 04:35

2 Answers2

1

You need to add the -lcrypt to LDFLAGS, because it is what is passed to the linker (not the `CFLAGS).

Jakuje
  • 24,773
  • 12
  • 69
  • 75
  • This sure worked, but for some reason i am not able to generate the executables. will update the OP and answer once i am able to close this. (umask 022 ; ./mkinstalldirs /var/empty) /usr/bin/install -c -m 0755 -s ssh /home/armsdk/Desktop/OpenSSH/OpenSSH_CC/bin/ssh strip: Unable to recognise the format of the input file `/home/armsdk/Desktop/OpenSSH/OpenSSH_CC/bin/ssh' /usr/bin/install: strip process terminated abnormally make: *** [install-files] Error 1 – Feroze Mohamed Jul 24 '17 at 11:47
  • You probably don't want to run `install` in your system. You install binary looks like it tries to strip the debuginfo or something from the binaries and does not know how to do that. – Jakuje Jul 24 '17 at 11:56
  • how else would i get the executables without the install command ? am i missing something here ? – Feroze Mohamed Jul 24 '17 at 13:40
  • 1
    Install is usually just a copy from some place to some other. You will find executables in build directory. – Jakuje Jul 24 '17 at 15:26
0

Solution was to

Add the libcrypt path to the compiler, for some reason the compiler couldnt find the right library

LDFLAGS='-L/home/cross-gcc-4.9.1-2.19-18-armv7a-soft/x86_64-pc-linux-gn‌​‌​u/arm-cortexa9-lin‌​ux‌​-gnueabi/sys-roo‌​t/li‌​b -lcrypt'

Added '--disable-strip' to overcome the STRIP error with the install command

My final configure command looks like this:

./configure --prefix=$HOME/Desktop/OpenSSH/OpenSSH_CC --host=arm --disable-strip --with-libs --with-zlib=$HOME/Desktop/Zlib/zlib-1.2.5/output --with-ssl-dir=$HOME/Desktop/OpenSSL/OpenSSL_CC --disable-etc-default-login CC=arm-cortexa9-linux-gnueabi-gcc AR=arm-cortexa9-linux-gnueabi-ar LDFLAGS='-L/home/cross-gcc-4.9.1-2.19-18-armv7a-soft/x86_64-pc-linux-gn‌​‌​u/arm-cortexa9-lin‌​ux‌​-gnueabi/sys-roo‌​t/li‌​b -lcrypt'
make
make install

Thanks to @Jakuje, @Gaurav Pathak and @k_kaz