You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

64位编译的iothub_client.so在32位Yocto设备运行报ELF类错误求助

Fixing "wrong ELF class: ELFCLASS64" for Azure IoT SDK Python on 32-bit Yocto

Let’s work through this issue—you’re running into a classic 64-bit vs 32-bit binary mismatch, and just adding -m32 directly to ./build.sh doesn’t work because the SDK’s build pipeline (which relies on an underlying C SDK) needs the 32-bit flag propagated across every compilation step. Here’s how to fix it:

Step 1: Set up 32-bit compilation dependencies on Ubuntu

First, you need to configure your 64-bit Ubuntu system to build 32-bit binaries. Install the multilib toolchain and 32-bit versions of the libraries the IoT SDK depends on:

sudo apt-get update
sudo apt-get install gcc-multilib g++-multilib libssl-dev:i386 libcurl4-openssl-dev:i386

Step 2: Propagate 32-bit flags globally

Instead of tacking -m32 onto build.sh, set environment variables that CMake (the SDK’s build system) will pick up for all compilation stages. Run these commands before executing build.sh:

export CFLAGS="-m32"
export CXXFLAGS="-m32"
export LDFLAGS="-m32"

This ensures every compiler and linker call uses 32-bit target settings.

Step 3: Explicitly set CMake flags (if needed)

If the environment variables don’t do the trick, modify the build.sh script to pass 32-bit flags directly to CMake. Look for the line where CMake is invoked (usually in the c subdirectory build steps) and update it to:

cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS="-m32" -DCMAKE_CXX_FLAGS="-m32"

This forces both the underlying C SDK and the Python wrapper to compile for 32-bit targets.

Step 4: Verify the output library

After compilation, confirm the generated iothub_client.so is a 32-bit binary with the file command:

file iothub_client.so

You should see output like ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked...—this confirms it’s compatible with your 32-bit Yocto device.

Why your initial attempt failed

The build.sh script delegates most compilation work to CMake for the Azure IoT C SDK. Adding -m32 directly to build.sh doesn’t pass the flag through to CMake’s compiler/linker configurations, so the build still produces 64-bit binaries. By setting environment variables or explicit CMake flags, you ensure every part of the pipeline targets 32-bit architecture.

内容的提问来源于stack exchange,提问作者J Greene

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 06:23:41