首页 > 解决方案 > 无法在 Raspberry PI3 上编译静态二进制文件

问题描述

我正在 Raspberry 设备上编译我的二进制文件,但是当我将它移动到另一个设备时,我收到以下错误:

./iot-relay
./iot-relay: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory`

我得出的结论是编译一个完全静态链接的二进制文件可能会有所帮助,所以我开始在这里阅读

添加我认为合适的目标:

rustup target add armv7-unknown-linux-musleabihf

并尝试编译:

cargo build --release --target armv7-unknown-linux-musleabihf

它编译了大部分内容,但随后:

error: failed to run custom build command for `paho-mqtt-sys v0.3.0`

Caused by:
  process didn't exit successfully: `/home/pi/rust/iot-relay/target/release/build/paho-mqtt-sys-9d34dbf9179b933d/build-script-build` (exit code: 101)
  --- stdout
  debug:Running the bundled build for Paho C
  cargo:rerun-if-changed=build.rs
  running: "cmake" "/home/pi/.cargo/registry/src/github.com-1285ae84e5963aae/paho-mqtt-sys-0.3.0/paho.mqtt.c/" "-DPAHO_BUILD_SHARED=off" "-DPAHO_BUILD_STATIC=on" "-DPAHO_ENABLE_TESTING=off" "-DPAHO_WITH_SSL=on" "-DCMAKE_INSTALL_PREFIX=/home/pi/rust/iot-relay/target/armv7-unknown-linux-musleabihf/release/build/paho-mqtt-sys-964264b133c84ace/out" "-DCMAKE_C_FLAGS= -ffunction-sections -fdata-sections -fPIC -march=armv7-a" "-DCMAKE_C_COMPILER=arm-linux-musleabihf-gcc" "-DCMAKE_CXX_FLAGS= -ffunction-sections -fdata-sections -fPIC -march=armv7-a" "-DCMAKE_CXX_COMPILER=arm-linux-musleabihf-g++" "-DCMAKE_ASM_FLAGS= -ffunction-sections -fdata-sections -fPIC -march=armv7-a" "-DCMAKE_ASM_COMPILER=arm-linux-musleabihf-gcc" "-DCMAKE_BUILD_TYPE=Release"
  -- The C compiler identification is unknown
  -- Configuring incomplete, errors occurred!
  See also "/home/pi/rust/iot-relay/target/armv7-unknown-linux-musleabihf/release/build/paho-mqtt-sys-964264b133c84ace/out/build/CMakeFiles/CMakeOutput.log".
  See also "/home/pi/rust/iot-relay/target/armv7-unknown-linux-musleabihf/release/build/paho-mqtt-sys-964264b133c84ace/out/build/CMakeFiles/CMakeError.log".

  --- stderr
  fatal: not a git repository (or any of the parent directories): .git
  CMake Error at CMakeLists.txt:21 (PROJECT):
    The CMAKE_C_COMPILER:

      arm-linux-musleabihf-gcc

    is not a full path and was not found in the PATH.

    Tell CMake where to find the compiler by setting either the environment
    variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
    the compiler, or to the compiler name if it is in the PATH.


  thread 'main' panicked at '
  command did not execute successfully, got: exit code: 1

  build script failed, must exit now', /home/pi/.cargo/registry/src/github.com-1285ae84e5963aae/cmake-0.1.44/src/lib.rs:885:5
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: build failed

我该如何解决这个问题并获得可以在我的其他 Raspberry 上运行的静态链接二进制文件?不幸的是,无法运行二进制文件的是自定义的,并且有一些自定义软件阻止我进行系统更新,所以我希望将所需的所有内容打包到我可以控制的二进制文件中。

标签: rustrust-cargo

解决方案


这是货物希望遵循 C 依赖项的构建说明,但没有找到支持指定工具链的 gcc。您可能需要为针对您的环境 (CC=) 的 gcc 找到正确的位置和名称。如果您没有针对该目标和 musl libc 组合的交叉编译器,则可能必须构建一个。有关如何执行此操作的信息,请参阅下面的链接。

https://wiki.musl-libc.org/getting-started.html


推荐阅读