交叉编译树莓派PCL时g++无法找到Boost头文件求助
Let’s break down what went wrong in your setup and walk through the corrected steps to get your cross-compilation working properly.
Key Issues You Overlooked
- Incorrect Cross-Compilation Root Filesystem: Your initial
debootstrapcommand didn’t specify the target architecture, so it created an x86_64 environment instead of an armhf one. This meant dependencies installed there were incompatible with your Raspberry Pi’s armv7l architecture. - Misplaced Boost Installation: You installed Boost to
/usr/includein an x86 chroot, but the cross-compiler looks for armhf-compatible headers in the armhf sysroot’s/usr/includedirectory, not the host/x86 path. - Missing
CMAKE_SYSROOTConfiguration: This critical CMake flag tells the build system to search for dependencies (Boost, FLANN, Eigen) inside the armhf root filesystem, preventing it from picking up mismatched x86 libraries/headers.
Corrected Step-by-Step Setup
1. Create a Proper Armhf Root Filesystem
First, replace your existing crossdev folder with an armhf-compatible one:
# Clean up the old incompatible folder sudo rm -rf crossdev_folder # Create armhf Debian Stretch root filesystem sudo debootstrap --arch=armhf stretch crossdev_folder http://deb.debian.org/debian/
2. Install Cross-Compiler on Your Host System
Install the arm-linux-gnueabihf GCC 8.3 toolchain directly on your host (not inside the chroot):
cd ~ wget https://developer.arm.com/-/media/Files/downloads/gnu-a/8.3-2019.03/binrel/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf.tar.xz tar -xvf gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf.tar.xz sudo cp -r gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/* /usr/ rm -rf gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf*
3. Cross-Compile Boost 1.67 to the Armhf Sysroot
Mount necessary system directories and compile Boost directly into the armhf root filesystem:
# Mount required filesystems for chroot sudo mount --bind /dev crossdev_folder/dev sudo mount --bind /proc crossdev_folder/proc sudo mount --bind /sys crossdev_folder/sys # Enter the armhf chroot environment sudo chroot crossdev_folder # Install dependencies for Boost compilation apt update && apt install -y unzip wget # Download and extract Boost cd /root wget https://dl.bintray.com/boostorg/release/1.67.0/source/boost_1_67_0.zip unzip boost_1_67_0.zip && rm boost_1_67_0.zip && cd boost_1_67_0/ # Configure Boost for armhf cross-compilation ./bootstrap.sh sed -i 's/using gcc ;/using gcc : arm : arm-linux-gnueabihf-g++ ;/' project-config.jam # Install Boost to the armhf sysroot (so cross-compiler can find it) ./bjam install toolset=gcc-arm --prefix=/usr -sNO_ZLIB=1 -sNO_BZIP2=1 # Exit chroot exit # Unmount system directories sudo umount crossdev_folder/sys sudo umount crossdev_folder/proc sudo umount crossdev_folder/dev
4. Install Armhf Dependencies in the Sysroot
Re-enter the chroot to install armhf versions of PCL’s required libraries:
sudo chroot crossdev_folder apt install -y libflann-dev libeigen3-dev libglu1-mesa-dev freeglut3-dev mesa-common-dev exit
5. Cross-Compile PCL with Correct CMake Settings
Now compile PCL with proper sysroot and path configuration:
cd ~ wget https://github.com/PointCloudLibrary/pcl/releases/download/pcl-1.11.1/source.zip unzip source.zip && rm source.zip && cd pcl/ mkdir build && cd build # Run CMake with sysroot and correct cross-compilation flags cmake -DCMAKE_C_COMPILER=arm-linux-gnueabihf-gcc \ -DCMAKE_CXX_COMPILER=arm-linux-gnueabihf-g++ \ -DCMAKE_SYSROOT=$(pwd)/../../crossdev_folder \ -DCMAKE_PREFIX_PATH=/usr \ -DWITH_VTK=OFF \ -DCMAKE_BUILD_TYPE=Release .. # Fix SSE detection for armv7l (since Pi 3B+ doesn't support x86 SSE) sed -i '11,16d' ../cmake/pcl_find_sse.cmake sed -i '10 a \ \ \ \ list(APPEND SSE_FLAGS "-marm")' ../cmake/pcl_find_sse.cmake # Compile PCL (use -j$(nproc) to speed up with all CPU cores) make -j$(nproc) VERBOSE=1 # Install PCL to the armhf sysroot (ready to copy to your Pi) sudo make install DESTDIR=$(pwd)/../../crossdev_folder
After completing these steps, the boost/mpl/assert.hpp not found error should be resolved, and subsequent architecture mismatch issues will disappear too. The compiled PCL libraries and headers will live inside your crossdev_folder—you can copy them to your Raspberry Pi’s /usr directory to use them.
内容的提问来源于stack exchange,提问作者afvmil

