交叉编译 OpenSSH 时出错(嵌入式 Linux)
Error cross compiling OpenSSH (Embedded Linux)
到目前为止已经学习了很多教程并且遇到了各种错误。以下是我遵循并最终在 OpenSSH 编译时出现错误的完整分步过程。
下载Zlib并交叉编译($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
已下载 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
获取密码错误:
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
请帮我解决。我只需要使用 gdbServer 进行远程调试的 SFTP-Server(通过 Eclipse)
在系统 运行 上编译:Debian Wheezy
目标板:嘉乐TX6S
目标处理器:NXP i.MX6S7
主机Linux版本:3.16.0-0.bpo.4-amd64
目标Linux版本:4.4.0-00118-g26d6b51
交叉编译器:gcc-arm-cortexa9-linux-gnueabi
更新一:
添加以下行给出错误:
-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
更新二:
按照此处的建议尝试了 -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
更新四:
更新 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-gnu/arm-cortexa9-linux-gnueabi/sys-root/lib 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:
我终于成功“制作”了,但无法'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-gnu/arm-cortexa9-linux-gnueabi/sys-root/lib -lcrypt'
make
make install
'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-gnu/arm-cortexa9-linux-gnueabi/sys-root/lib -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
您需要将 -lcrypt
添加到 LDFLAGS
,因为它是传递给链接器的内容(而不是 `CFLAGS)。
解决方案是
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-gnu/arm-cortexa9-linux-gnueabi/sys-root/lib -lcrypt'
Added '--disable-strip' to overcome the STRIP error with the install command
我的最终配置命令如下所示:
./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-gnu/arm-cortexa9-linux-gnueabi/sys-root/lib -lcrypt'
make
make install
感谢@Jakuje、@Gaurav Pathak 和@k_kaz
到目前为止已经学习了很多教程并且遇到了各种错误。以下是我遵循并最终在 OpenSSH 编译时出现错误的完整分步过程。
下载Zlib并交叉编译($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
已下载 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
获取密码错误:
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
请帮我解决。我只需要使用 gdbServer 进行远程调试的 SFTP-Server(通过 Eclipse)
在系统 运行 上编译:Debian Wheezy
目标板:嘉乐TX6S
目标处理器:NXP i.MX6S7
主机Linux版本:3.16.0-0.bpo.4-amd64
目标Linux版本:4.4.0-00118-g26d6b51
交叉编译器:gcc-arm-cortexa9-linux-gnueabi
更新一:
添加以下行给出错误:
-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
更新二:
按照此处的建议尝试了 -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
更新四: 更新 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-gnu/arm-cortexa9-linux-gnueabi/sys-root/lib 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:
我终于成功“制作”了,但无法'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-gnu/arm-cortexa9-linux-gnueabi/sys-root/lib -lcrypt'
make
make install
'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-gnu/arm-cortexa9-linux-gnueabi/sys-root/lib -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
您需要将 -lcrypt
添加到 LDFLAGS
,因为它是传递给链接器的内容(而不是 `CFLAGS)。
解决方案是
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-gnu/arm-cortexa9-linux-gnueabi/sys-root/lib -lcrypt'
Added '--disable-strip' to overcome the STRIP error with the install command
我的最终配置命令如下所示:
./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-gnu/arm-cortexa9-linux-gnueabi/sys-root/lib -lcrypt'
make
make install
感谢@Jakuje、@Gaurav Pathak 和@k_kaz