linuxgcccross-compilinglibssh2

Cross-compiling libssh2 on Ubuntu


I'm running an Ubuntu 22.04 x64 machine. I'm trying to cross-compile libssh2 for ARMv7. I'm using this compiler: gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf

Running configure with these options succeeds (using g++):

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

but when I link the newly built library the linker complains "libssh2.so. File format not recognized".

Note that I am successfully linking against an older version of libssh2 that someone else built with the same compiler months ago.

If I run configure with gcc, with these options, it fails:

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

It says: "C compiler cannot create executables" and a relevant part of the log file is this:

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

Any help will be appreciated.


Solution

  • For anyone wondering and for my future self, I got the compilation working with this command:

    ./configure CC=/path/to/arm-linux-gnueabihf-gcc --host=arm-linux-gnueabihf --with-crypto=openssl --with-libssl-prefix=/path/to/openssl/build-3.3.1 --prefix=/path/to/libssh2/build-1.11.0 --with-libz --with-libz-prefix=/path/to/zlib/build-1.2.13 LDFLAGS="-L/path/to/openssl/build-3.3.1/lib -lcrypto -lssl -L/path/to/zlib/build-1.2.13/lib -lz"
    

    LDFLAGS did the trick.