在 Ubuntu 上交叉编译 libssh2

Cross-compiling libssh2 on Ubuntu

提问人:Nikzeno 提问时间:10/12/2023 最后编辑:FrantNikzeno 更新时间:10/29/2023 访问量:68

问:

我正在运行 Ubuntu 22.04 x64 机器。我正在尝试为 ARMv2 交叉编译 libssh7。 我正在使用这个编译器:gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf

使用以下选项运行 configure 成功(使用 g++):

CXX=/path/to/arm-linux-gnueabihf-g++  
--host=arm-linux-gnueabihf  
--with-libssl-prefix=[DIR]  
CXXFLAGS=-m32  

但是当我链接新建的库时,链接器抱怨“libssh2.so。无法识别文件格式”。

请注意,我成功地链接到了其他人几个月前使用同一编译器构建的旧版本的 libssh2。

如果我使用 gcc 运行 configure,使用这些选项,它会失败:

CC=/path/to/arm-linux-gnueabihf-gcc  
--host=arm-linux-gnueabihf  
--with-libssl-prefix=[DIR]  
CFLAGS=-m32  

它说:“C 编译器无法创建可执行文件”,日志文件的相关部分是这样的:

configure:4032: checking for arm-linux-gnueabihf-gcc
configure:4064: result: /path/to/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc
configure:4462: checking for C compiler version
configure:4471: /path/to/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc --version >&5
arm-linux-gnueabihf-gcc (Linaro GCC 7.5-2019.12) 7.5.0
Copyright (C) 2017 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.

configure:4482: $? = 0
configure:4471: /path/to/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc -v >&5
Using built-in specs.
COLLECT_GCC=/path/to/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc
COLLECT_LTO_WRAPPER=/path/to/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/../libexec/gcc/arm-linux-gnueabihf/7.5.0/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: '/home/tcwg-buildslave/workspace/tcwg-make-release_1/snapshots/gcc.git~linaro-7.5-2019.12/configure' SHELL=/bin/bash --with-mpc=/home/tcwg-buildslave/workspace/tcwg-make-release_1/_build/builds/destdir/x86_64-unknown-linux-gnu --with-mpfr=/home/tcwg-buildslave/workspace/tcwg-make-release_1/_build/builds/destdir/x86_64-unknown-linux-gnu --with-gmp=/home/tcwg-buildslave/workspace/tcwg-make-release_1/_build/builds/destdir/x86_64-unknown-linux-gnu --with-gnu-as --with-gnu-ld --disable-libmudflap --enable-lto --enable-shared --without-included-gettext --enable-nls --with-system-zlib --disable-sjlj-exceptions --enable-gnu-unique-object --enable-linker-build-id --disable-libstdcxx-pch --enable-c99 --enable-clocale=gnu --enable-libstdcxx-debug --enable-long-long --with-cloog=no --with-ppl=no --with-isl=no --disable-multilib --with-float=hard --with-fpu=vfpv3-d16 --with-mode=thumb --with-tune=cortex-a9 --with-arch=armv7-a --enable-threads=posix --enable-multiarch --enable-libstdcxx-time=yes --enable-gnu-indirect-function --with-build-sysroot=/home/tcwg-buildslave/workspace/tcwg-make-release_1/_build/sysroots/arm-linux-gnueabihf --with-sysroot=/home/tcwg-buildslave/workspace/tcwg-make-release_1/_build/builds/destdir/x86_64-unknown-linux-gnu/arm-linux-gnueabihf/libc --enable-checking=release --disable-bootstrap --enable-languages=c,c++,fortran,lto --build=x86_64-unknown-linux-gnu --host=x86_64-unknown-linux-gnu --target=arm-linux-gnueabihf --prefix=/home/tcwg-buildslave/workspace/tcwg-make-release_1/_build/builds/destdir/x86_64-unknown-linux-gnu
Thread model: posix
gcc version 7.5.0 (Linaro GCC 7.5-2019.12) 
configure:4482: $? = 0
configure:4471: /path/to/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc -V >&5
arm-linux-gnueabihf-gcc: error: unrecognized command line option '-V'
arm-linux-gnueabihf-gcc: fatal error: no input files
compilation terminated.
configure:4482: $? = 1
configure:4471: /path/to/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc -qversion >&5
arm-linux-gnueabihf-gcc: error: unrecognized command line option '-qversion'; did you mean '--version'?
arm-linux-gnueabihf-gcc: fatal error: no input files
compilation terminated.
configure:4482: $? = 1
configure:4471: /path/to/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc -version >&5
arm-linux-gnueabihf-gcc: error: unrecognized command line option '-version'
arm-linux-gnueabihf-gcc: fatal error: no input files
compilation terminated.
configure:4482: $? = 1
configure:4502: checking whether the C compiler works
configure:4524: /path/to/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc -m32   conftest.c  >&5
arm-linux-gnueabihf-gcc: error: unrecognized command line option '-m32'
configure:4528: $? = 1
configure:4568: result: no

任何帮助将不胜感激。

Linux GCC 交叉编译 libssh2

评论

0赞 jcmvbkbc 10/12/2023
以下部分建议您应该从 CFLAGS 中删除,因为此编译器不支持它。arm-linux-gnueabihf-gcc: error: unrecognized command line option '-m32'-m32
0赞 Nikzeno 10/12/2023
如果我省略了适用于 g++ 的标志,则配置甚至在抱怨它找不到 libssl 之前就结束了
0赞 jcmvbkbc 10/12/2023
它不适用于 g++,请检查您的配置 .log。它只是没有传递给 c 编译器。
0赞 jcmvbkbc 10/12/2023
如果它找不到libssl,那么这就是需要首先解决的问题。

答: 暂无答案