Search code examples
cmakemakefilecross-compilinglibsshlibnetconf2

Cross-compiling for ARM while linking to libssh: file not recognized


I am trying to cross-compile the libssh libraries with ARM architecture so that I can cross-compile another library (netconf2) which needs libssh. So that I can cross-compile my server code made on netconf2.

I read the Readme file and I beleive I have followed the correct procedures. The cmake command I executed is:

cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=/home/zen/Downloads/armv7-marvell-linux-gnueabi -DCMAKE_C_COMPILER=/home/zen/Downloads/armv7-marvell-linux-gnueabi/bin/arm-marvell-linux-gnueabi-gcc -DCMAKE_CXX_COMPILER=/home/zen/Downloads/armv7-marvell-linux-gnueabi/bin/arm-marvell-linux-gnueabi-g++ -DWITH_ZLIB=OFF 

armv7-marvell-linux-gnueabi is the cross-compiler tool chain.

I am getting the following error:

[ 54%] Linking C shared library ../lib/libssh.so
/usr/lib/x86_64-linux-gnu/libcrypto.so: file not recognized: File format not recognized
collect2: ld returned 1 exit status
make[2]: *** [src/CMakeFiles/ssh.dir/build.make:1202: lib/libssh.so.4.9.0] Error 1
make[1]: *** [CMakeFiles/Makefile2:251: src/CMakeFiles/ssh.dir/all] Error 2
make: *** [Makefile:156: all] Error 2

Here is the relevant part of INSTALL file of Libssh git folder:

Here is a list of the most interesting options provided out of the box by
CMake.

- CMAKE_BUILD_TYPE:     The type of build (can be Debug Release MinSizeRel
                        RelWithDebInfo)
- CMAKE_INSTALL_PREFIX: The prefix to use when running make install (Default
                        to /usr/local on GNU/Linux and MacOS X)
- CMAKE_C_COMPILER:     The path to the C compiler
- CMAKE_CXX_COMPILER:   The path to the C++ compiler

### CMake options defined for libssh

Options are defined in the following files:

- DefineOptions.cmake

They can be changed with the -D option:

`cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug -DWITH_ZLIB=OFF ..

I think it is trying to get the file from my default lib folder. But I have no idea why and how I can change that. Please help.


Solution

  • I found a way to fix it by using ccmake .. in build directory.

    (Make sure your cross-compiler library and include folders have the needed libraries which are also cross-compiled for ARM.)

    And just in-case your ccmake won't work for some reason, you can use the same variables you see in ccmake with cmake instead:

    cmake .. \
      -DCMAKE_BUILD_TYPE=Debug \
      -DCMAKE_INSTALL_PREFIX=your_install_path \
      -DCMAKE_C_COMPILER=armv7l-linux-musleabihf-gcc \
      -DCMAKE_CXX_COMPILER=armv7l-linux-musleabihf-c++ \
      -DCMAKE_C_COMPILER_AR=armv7l-linux-musleabihf-gcc-ar \
      -DCMAKE_C_COMPILER_RANLIB=armv7l-linux-musleabihf-gcc-ranlib \
      -DCMAKE_CXX_COMPILER_AR=armv7l-linux-musleabihf-gcc-ar \
      -DCMAKE_CXX_COMPILER_RANLIB=armv7l-linux-musleabihf-gcc-ranlib \
      -DOPENSSL_INCLUDE_DIR=armv7l-linux-musleabihf/include/openssl \
      -DOPENSSL_CRYPTO_LIBRARY=armv7l-linux-musleabihf/lib/libcrypto.so \
      -DOPENSSL_SSL_LIBRARY=armv7l-linux-musleabihf/lib/libssl.so \
      -DZLIB_INCLUDE_DIR=armv7l-linux-musleabihf/include \
      -DZLIB_LIBRARY_RELEASE=armv7l-linux-musleabihf/lib/libz.so \
      -DWITH_ZLIB=ON \
      -DPKG_CONFIG_EXECUTABLE=armv7l-linux-musleabihf/lib/pkgconfig \
      -DLIBSSH_INCLUDE_DIR=armv7l-linux-musleabihf/include/libssh \
      -DLIBSSH_LIBRARY=armv7l-linux-musleabihf/lib/libssh.so
    

    (Don't forget to edit the variable values as required.)