64位编译的iothub_client.so在32位Yocto设备运行报ELF类错误求助
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

