Paho C (ARM) 的交叉编译问题

Problem with cross compilation of Paho C (ARM)

我需要帮助,因为我尝试用 c 语言为我的 arm 设备交叉编译 paho 库。

我使用 ubuntu 20.04 虚拟机,我的交叉编译器是 gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf_5.3_sub1.0.3.tgz。这里是不同的步骤。

git clone https://github.com/eclipse/paho.mqtt.c.git

sudo apt-get update
sudo apt-get install build-essential gcc make cmake cmake-gui cmake-curses-gui
sudo apt-get install fakeroot fakeroot devscripts dh-make lsb-release
sudo apt-get install libssl-dev 
sudo apt-get install doxygen graphviz
mkdir build.paho
cd build.paho

我在 paho 项目的 cmake 文件夹中创建了一个文件“linaro.cmake”

 # specify the cross compiler

SET(CMAKE_C_COMPILER    /opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc)
SET(CMAKE_CXX_COMPILER  /opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++)
SET(CMAKE_STRIP /opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-strip)

#SET(OPENSSL_LIB_SEARCH_PATH opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/lib)
#SET(OPENSSL_INC_SEARCH_PATH opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/include/openssl)
#SET(OPENSSL_SEARCH_PATH "/opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/lib;/opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/bin/")

SET(OPENSSL_ROOT_DIR /opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/bin)
SET(OPENSSL_LIBRARIES /opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/lib)
#SET(OPENSSL_LIBRARIES /opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/include/openssl)
SET(OPENSSL_INCLUDE_DIR /opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/include/openssl)
SET(OPENSSL_CRYPTO_LIBRARY /opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/include/openssl/libcrypto.so)
SET(OPENSSL_SSL_LIBRARY /opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/lib/libssl.so)

SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_PROCESSOR arm)
SET(CMAKE_SYSTEM_VERSION 1)

我的问题,当我启动命令时

cmake \
-GNinja \
-DPAHO_WITH_SSL=TRUE \
-DPAHO_BUILD_SAMPLES=TRUE \
-DPAHO_BUILD_DOCUMENTATION=TRUE \
-DCMAKE_TOOLCHAIN_FILE=../cmake/linaro.cmake ..

我有多个警告,例如

-- The C compiler identification is GNU 5.3.1 -- Check for working C compiler: /opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc -- Check for working C compiler: /opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- CMake version: 3.16.3 -- CMake system name: Linux -- Timestamp is 2021-05-04T12:39:01Z -- Found OpenSSL: /opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/bin/libcrypto.so

-- Configuring done CMake Warning (dev) at src/CMakeLists.txt:200 (ADD_LIBRARY): Policy CMP0028 is not set: Double colon in target name means ALIAS or IMPORTED target. Run "cmake --help-policy CMP0028" for policy details. Use the cmake_policy command to set the policy and suppress this warning.

Target "paho-mqtt3cs" links to target "OpenSSL::Crypto" but the target was not found. Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing? This warning is for project developers. Use -Wno-dev to suppress it.

CMake Warning (dev) at src/CMakeLists.txt:201 (ADD_LIBRARY): Policy CMP0028 is not set: Double colon in target name means ALIAS or
IMPORTED target. Run "cmake --help-policy CMP0028" for policy details. Use the cmake_policy command to set the policy and suppress this warning.

Target "paho-mqtt3as" links to target "OpenSSL::Crypto" but the target was not found. Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing? This warning is for project developers. Use -Wno-dev to suppress it.

CMake Warning (dev) at src/CMakeLists.txt:332 (ADD_EXECUTABLE):
Policy CMP0028 is not set: Double colon in target name means ALIAS or IMPORTED target. Run "cmake --help-policy CMP0028" for policy details. Use the cmake_policy command to set the policy and suppress this warning.

Target "Sha1TestOpenSSL" links to target "OpenSSL::Crypto" but the target was not found. Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing? This warning is for project developers. Use -Wno-dev to suppress it.

CMake Warning (dev) at src/CMakeLists.txt:323 (ADD_EXECUTABLE):
Policy CMP0028 is not set: Double colon in target name means ALIAS or IMPORTED target. Run "cmake --help-policy CMP0028" for policy details. Use the cmake_policy command to set the policy and suppress this warning.

Target "Base64TestOpenSSL" links to target "OpenSSL::Crypto" but the target was not found. Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing? This warning is for project developers. Use -Wno-dev to suppress it.

CMake Warning (dev) at test/CMakeLists.txt:516 (ADD_EXECUTABLE):
Policy CMP0028 is not set: Double colon in target name means ALIAS or IMPORTED target. Run "cmake --help-policy CMP0028" for policy details. Use the cmake_policy command to set the policy and suppress this warning.

Target "test3" links to target "OpenSSL::Crypto" but the target was not found. Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing? This warning is for project developers. Use -Wno-dev to suppress it.

CMake Warning (dev) at test/CMakeLists.txt:1122 (ADD_EXECUTABLE):
Policy CMP0028 is not set: Double colon in target name means ALIAS or IMPORTED target. Run "cmake --help-policy CMP0028" for policy details. Use the cmake_policy command to set the policy and suppress this warning.

Target "test5" links to target "OpenSSL::Crypto" but the target was not found. Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing? This warning is for project developers. Use -Wno-dev to suppress it.

-- Generating done -- Build files have been written to: /home/myhome/Documents/paho.mqtt.c/build.paho

当我尝试启动 ninja 包时

[9/50] Linking C shared library src/libpaho-mqtt3cs.so.1.3.8 FAILED: src/libpaho-mqtt3cs.so.1.3.8 : && /opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc -fPIC -Wl,-init,MQTTClient_init -shared -Wl,-soname,libpaho-mqtt3cs.so.1 -o src/libpaho-mqtt3cs.so.1.3.8 src/CMakeFiles/common_ssl_obj.dir/MQTTTime.c.o src/CMakeFiles/common_ssl_obj.dir/MQTTProtocolClient.c.o src/CMakeFiles/common_ssl_obj.dir/Clients.c.o src/CMakeFiles/common_ssl_obj.dir/utf-8.c.o src/CMakeFiles/common_ssl_obj.dir/MQTTPacket.c.o src/CMakeFiles/common_ssl_obj.dir/MQTTPacketOut.c.o src/CMakeFiles/common_ssl_obj.dir/Messages.c.o src/CMakeFiles/common_ssl_obj.dir/Tree.c.o src/CMakeFiles/common_ssl_obj.dir/Socket.c.o src/CMakeFiles/common_ssl_obj.dir/Log.c.o src/CMakeFiles/common_ssl_obj.dir/MQTTPersistence.c.o src/CMakeFiles/common_ssl_obj.dir/Thread.c.o src/CMakeFiles/common_ssl_obj.dir/MQTTProtocolOut.c.o src/CMakeFiles/common_ssl_obj.dir/MQTTPersistenceDefault.c.o src/CMakeFiles/common_ssl_obj.dir/SocketBuffer.c.o src/CMakeFiles/common_ssl_obj.dir/LinkedList.c.o src/CMakeFiles/common_ssl_obj.dir/MQTTProperties.c.o src/CMakeFiles/common_ssl_obj.dir/MQTTReasonCodes.c.o src/CMakeFiles/common_ssl_obj.dir/Base64.c.o src/CMakeFiles/common_ssl_obj.dir/SHA1.c.o src/CMakeFiles/common_ssl_obj.dir/WebSocket.c.o src/CMakeFiles/common_ssl_obj.dir/StackTrace.c.o src/CMakeFiles/common_ssl_obj.dir/Heap.c.o src/CMakeFiles/paho-mqtt3cs.dir/MQTTClient.c.o src/CMakeFiles/paho-mqtt3cs.dir/SSLSocket.c.o /opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/lib/libssl.so -lOpenSSL::Crypto -lc -ldl -lpthread -lrt && : /opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/5.3.1/../../../../arm-linux-gnueabihf/bin/ld : ne peut trouver -lOpenSSL::Crypto collect2: error: ld returned 1 exit status [11/50] Building C object src/CMakeFiles/paho-mqtt3as.dir/SSLSocket.c.o ninja: build stopped: subcommand failed.

有人知道吗?

对我来说奇怪的是这一行 -- 发现 OpenSSL:/opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/bin/libcrypto.so 即使我指出了另一个位置。

提前致谢

已使用新编译器 gcc-arm-8.3-2019 解决。03-x86_64-arm-linux-gnueabihf。