如何为ARMHF架构交叉编译Ubertooth主机软件?
Alright, let’s walk through how to get your Ubertooth host software cross-compiled for ARMHF—since you’ve already nailed the x64 build, this should be straightforward with the right setup. The core idea is telling CMake to use an ARMHF-specific toolchain instead of your host’s x64 compiler, plus ensuring dependencies are ARM-compatible. Here’s the step-by-step breakdown:
1. Install the ARMHF Cross-Compile Toolchain
On Debian/Ubuntu-based systems, you can grab pre-built toolchain packages directly via apt:
sudo apt update && sudo apt install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf
This installs the arm-linux-gnueabihf-gcc and arm-linux-gnueabihf-g++ compilers, along with supporting utilities needed for cross-compilation.
2. Create a CMake Toolchain File
CMake needs explicit instructions to target ARMHF. Create a file named armhf-toolchain.cmake in your Ubertooth source directory with these contents:
# Define the target system set(CMAKE_SYSTEM_NAME Linux) set(CMAKE_SYSTEM_PROCESSOR arm) # Specify the cross-compilers set(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc) set(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++) # Optional: If you have a dedicated ARMHF root filesystem (e.g., mounted Raspberry Pi image), point to it here # set(CMAKE_SYSROOT /path/to/your/armhf-rootfs) # Prevent CMake from checking host system libraries/tools set(CMAKE_C_COMPILER_TARGET arm-linux-gnueabihf) set(CMAKE_CXX_COMPILER_TARGET arm-linux-gnueabihf) set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
The CMAKE_SYSROOT line is optional but useful if you want to use pre-built ARMHF libraries from a full root filesystem instead of cross-compiling dependencies yourself.
3. Handle Dependencies (Critical Step!)
Ubertooth relies on libraries like libusb-1.0. You have two solid options here:
- Option A: Use multiarch to install ARMHF pre-built libraries (easiest on Debian/Ubuntu):
This enables your system to host both x64 and ARMHF libraries, so the cross-compiler can find the ARM version of libusb.sudo dpkg --add-architecture armhf sudo apt update sudo apt install libusb-1.0-0-dev:armhf - Option B: Cross-compile dependencies manually: If multiarch isn’t an option, download the libusb source code, use the same ARMHF toolchain to compile it, and install it to a directory (or your ARMHF rootfs) that CMake can find.
4. Run CMake, Make, and Install
Now, use the toolchain file to configure and build for ARMHF. It’s best to use a clean build directory to avoid conflicts with your x64 build:
# Create and enter a dedicated ARMHF build directory mkdir build-armhf && cd build-armhf # Configure CMake with the toolchain file cmake .. -DCMAKE_TOOLCHAIN_FILE=../armhf-toolchain.cmake # Optional: Specify an install directory (instead of system paths) to easily copy files to your ARM device # cmake .. -DCMAKE_TOOLCHAIN_FILE=../armhf-toolchain.cmake -DCMAKE_INSTALL_PREFIX=/path/to/armhf-install # Build and install make -j$(nproc) # Use all available CPU cores for faster builds make install
If you set CMAKE_INSTALL_PREFIX, all compiled binaries and libraries will end up in that directory—just copy them over to your ARMHF device when done.
Quick Troubleshooting Tips
- If CMake complains about missing libraries, double-check that your ARMHF dependencies are installed correctly and that the toolchain file’s paths point to the right locations.
- Avoid mixing host (x64) and target (ARMHF) libraries—this is exactly why the
CMAKE_FIND_ROOT_PATH_MODE_*settings in the toolchain file are there to enforce strict library searching for ARMHF.
内容的提问来源于stack exchange,提问作者Eng_Mike

