链接到 libssh 时对 ARM 进行交叉编译:无法识别文件

问题描述 投票:0回答:1

我正在尝试使用ARM架构交叉编译libssh库,以便我可以交叉编译另一个需要libssh的库(netconf2)。这样我就可以交叉编译我在 netconf2 上编写的服务器代码。

我阅读了自述文件,我相信我遵循了正确的程序。我执行的cmake命令是:

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 是交叉编译器工具链。

我收到以下错误:

[ 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

这是 Libssh git 文件夹的 INSTALL 文件的相关部分:

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

我认为它正在尝试从我的默认 lib 文件夹中获取文件。但我不知道为什么以及如何改变它。 请帮忙。

cmake makefile cross-compiling libssh libnetconf2
1个回答
0
投票

我找到了一种通过在构建目录中使用

ccmake ..
来修复它的方法。

(确保您的交叉编译器库和包含文件夹具有所需的库,这些库也是针对 ARM 进行交叉编译的。)

万一您的

ccmake
由于某种原因无法工作,您可以将
ccmake
中看到的相同变量与
cmake
一起使用:

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
© www.soinside.com 2019 - 2024. All rights reserved.