错误交叉编译OpenSSH(嵌入式Linux)

时间:2017-07-24 07:43:53

标签: c cross-compiling embedded-linux openssh

到目前为止已经有很多教程,并且有各种错误。下面是我遵循的完整的一步一步程序,最后在OpenSSH编译时出错。

下载Zlib并交叉编译($ HOME / Desktop / Zlib / zlib-1.2.5 /输出)

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

下载OpenSSL并交叉编译:($ 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

交叉编译的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

获得CRYPT错误:

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

请帮我解决。我需要的是SFTP-Server,用于使用gdbServer(通过Eclipse)进行远程调试

在系统运行时进行编译:Debian Wheezy

目标董事会:Ka-Ro TX6S

目标处理器:恩智浦i.MX6S7

主机Linux版:3.16.0-0.bpo.4-amd64

目标Linux版本:4.4.0-00118-g26d6b51

CrossCompiler :gcc-arm-cortexa9-linux-gnueabi

更新1:

添加以下行Gave错误:

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

错误

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

尝试了这一点,但CRYPT错误仍然存​​在。

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

更新2:

在此处建议尝试-lcrypt标志:undefined reference to `crypt'但这不会有任何错误更改。

make clean
make -lcrypt

更新3: 添加了' CFLAGS = -lcrypt'并且错误现在已更改

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

错误

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

更新4: 更新了LDFLAGS和CFLAGS,如下所示:

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

问题仍然相同:

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

更新5:

我终于成功了“制作”但却无法安装'

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

安装'

时出错
(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

更新6:希望最终

所以我最终能够通过添加标志' - 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

但是有一个小问题,我有这个错误:

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

2 个答案:

答案 0 :(得分:1)

您需要将-lcrypt添加到LDFLAGS,因为它是传递给链接器的内容(而不是`CFLAGS)。

答案 1 :(得分:0)

解决方案是

  

将libcrypt路径添加到编译器,由于某种原因,编译器无法找到正确的库

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'
  

添加'--disable-strip'以使用安装命令

克服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

感谢@Jakuje,@ Gaurav Pathak和@k_kaz