g++找不到交叉编译的boost标头



编辑

添加了更多信息以重现错误。


我想将复盆子Pi 3B+(armv7l(的PCL与GCC 8.3交叉编译。为此,我需要提升1.67,因为这是我目前在Pi中的库。我就是这样做的:

sudo debootstrap stretch crossdev_folder
sudo chroot crossdev_folder
apt install -y unzip cmake cmake-curses-gui xz-utils
cd /root/

然后我从这里下载带有硬浮动(arm-linux-gneabihf(GCC 8.3的AArch32目标,并将其内容复制到/usr/

tar -xvf gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf.tar.xz
cd gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/
rm *.txt && cp -r ./* /usr/ && cd /root/
rm -r gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/

然后我交叉编译libboost 1.6.7

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/
./bootstrap.sh
sed -i 's/using gcc ;/using gcc : arm : arm-linux-gnueabihf-g++ ;/' project-config.jam
./bjam install toolset=gcc-arm --prefix=/usr -sNO_ZLIB=1 -sNO_BZIP2=1

为了确保我已经安装了它们,我转到/usr/include/,boost/文件夹中有所有的标题。(例如boost/mpl/assert.hpp(

root@felipe:/root# cd /usr/include/
root@felipe:/usr/include# ls boost/mpl/assert.hpp 
boost/mpl/assert.hpp

然后我交叉编译并安装OpenCV-3.4.9(因为我也需要它(,最后我尝试像这个一样交叉编译PCL

# First install some dependencies
apt-get install -y libflann-dev:armhf libeigen3-dev:armhf libglu1-mesa-dev:armhf freeglut3-dev:armhf mesa-common-dev:armhf
# Download PCL
cd /root/
wget https://github.com/PointCloudLibrary/pcl/releases/download/pcl-1.11.1/source.zip
unzip source.zip && rm source.zip && cd pcl/
# Do CMake
mkdir build && cd build
cmake -DCMAKE_C_COMPILER=arm-linux-gnueabihf-gcc 
-DCMAKE_CXX_COMPILER=arm-linux-gnueabihf-g++ 
-DWITH_VTK=OFF ..

在这里,我发现了第一个问题,因为CMake找不到FLANN,它已经安装了apt,我可以在中找到它的.pc

root@felipe:/root/pcl/build# ls /usr/lib/arm-linux-gnueabihf/pkgconfig/
dri.pc               libdrm_nouveau.pc    xau.pc               xcb-xfixes.pc
flann.pc             libdrm_omap.pc       xcb-dri2.pc          xcb.pc
gl.pc                libdrm_radeon.pc     xcb-dri3.pc          xdamage.pc
glu.pc               libdrm_tegra.pc      xcb-glx.pc           xdmcp.pc
ice.pc               libdrm_vc4.pc        xcb-present.pc       xext.pc
libdrm.pc            pthread-stubs.pc     xcb-randr.pc         xfixes.pc
libdrm_amdgpu.pc     sm.pc                xcb-render.pc        xshmfence.pc
libdrm_exynos.pc     x11-xcb.pc           xcb-shape.pc         xt.pc
libdrm_freedreno.pc  x11.pc               xcb-sync.pc          xxf86vm.pc

因此,我必须使用-DCMAKE_PREFIX_PATH=/usr/lib/arm-linux-gnueabihf执行cmake,以指定以前安装的所有:armhf库的安装前缀。由于cmake版本,我收到了一些Boost警告,但似乎找到了正确的 Boost库

CMake Warning at /usr/share/cmake-3.7/Modules/FindBoost.cmake:761 (message):
Imported targets not available for Boost version 106700
Call Stack (most recent call first):
/usr/share/cmake-3.7/Modules/FindBoost.cmake:865 (_Boost_COMPONENT_DEPENDENCIES)
/usr/share/cmake-3.7/Modules/FindBoost.cmake:1470 (_Boost_MISSING_DEPENDENCIES)
cmake/pcl_find_boost.cmake:33 (find_package)
CMakeLists.txt:462 (include)

-- Boost version: 1.67.0
-- Found the following Boost libraries:
--   filesystem
--   date_time
--   iostreams
--   system

交叉编译的一些变化:

# remove some lines from CMake files
sed -i '11,16d' ../cmake/pcl_find_sse.cmake && sed -i '10 a      list(APPEND SSE_FLAGS "-marm")' ../cmake/pcl_find_sse.cmake

在这里,当我尝试编译时,它失败了,因为它找不到boost标头编辑:添加VERBOSE=1以生成

root@felipe:/root/pcl/build# make VERBOSE=1
/usr/local/bin/cmake -S/root/pcl -B/root/pcl/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/local/bin/cmake -E cmake_progress_start /root/pcl/build/CMakeFiles /root/pcl/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/root/pcl/build'
make -f common/CMakeFiles/pcl_common.dir/build.make common/CMakeFiles/pcl_common.dir/depend
make[2]: Entering directory '/root/pcl/build'
cd /root/pcl/build && /usr/local/bin/cmake -E cmake_depends "Unix Makefiles" /root/pcl /root/pcl/common /root/pcl/build /root/pcl/build/common /root/pcl/build/common/CMakeFiles/pcl_common.dir/DependInfo.cmake --color=
Dependee "/root/pcl/build/common/CMakeFiles/pcl_common.dir/DependInfo.cmake" is newer than depender "/root/pcl/build/common/CMakeFiles/pcl_common.dir/depend.internal".
Dependee "/root/pcl/build/common/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/root/pcl/build/common/CMakeFiles/pcl_common.dir/depend.internal".
Scanning dependencies of target pcl_common
make[2]: Leaving directory '/root/pcl/build'
make -f common/CMakeFiles/pcl_common.dir/build.make common/CMakeFiles/pcl_common.dir/build
make[2]: Entering directory '/root/pcl/build'
[  0%] Building CXX object common/CMakeFiles/pcl_common.dir/src/point_types.cpp.o
cd /root/pcl/build/common && /usr/bin/arm-linux-gnueabihf-g++  -DPCLAPI_EXPORTS -I/root/pcl/build/include -I/root/pcl/common/include -isystem /usr/include/eigen3 -isystem /root/pcl/recognition/include/pcl/recognition/3rdparty  -Wabi=11 -Wall -Wextra -Wno-unknown-pragmas -fno-strict-aliasing -Wno-format-extra-args -Wno-sign-compare -Wno-invalid-offsetof -Wno-conversion -marm -ffloat-store -fopenmp -O2 -g -DNDEBUG -fPIC   -fopenmp -std=c++14 -o CMakeFiles/pcl_common.dir/src/point_types.cpp.o -c /root/pcl/common/src/point_types.cpp
In file included from /root/pcl/common/include/pcl/type_traits.h:40,
from /root/pcl/common/include/pcl/memory.h:46,
from /root/pcl/common/include/pcl/impl/point_types.hpp:41,
from /root/pcl/common/include/pcl/point_types.h:349,
from /root/pcl/common/src/point_types.cpp:37:
/root/pcl/common/include/pcl/point_struct_traits.h:42:10: fatal error: boost/mpl/assert.hpp: No such file or directory
#include <boost/mpl/assert.hpp>  // for BOOST_MPL_ASSERT_MSG
^~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
common/CMakeFiles/pcl_common.dir/build.make:62: recipe for target 'common/CMakeFiles/pcl_common.dir/src/point_types.cpp.o' failed
make[2]: *** [common/CMakeFiles/pcl_common.dir/src/point_types.cpp.o] Error 1
make[2]: Leaving directory '/root/pcl/build'
CMakeFiles/Makefile2:122: recipe for target 'common/CMakeFiles/pcl_common.dir/all' failed
make[1]: *** [common/CMakeFiles/pcl_common.dir/all] Error 2
make[1]: Leaving directory '/root/pcl/build'
Makefile:151: recipe for target 'all' failed
make: *** [all] Error 2

知道我错过了什么吗?非常感谢。

更新

当我在/usr/local中使用--prefix=/usr/local安装boost时,编译器实际上可以找到标头(我还必须移动flann标头(。我终于得到了另一个错误,但这主要与这个有关

如果cmake无法自动添加路径。使用:link_directoriesinclude_directories

您也可以在运行cmake命令之前导出CXXFLAGS。从…起https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_FLAGS_INIT.html#variable:CMAKE_%3CLANG%3E_FLAGS_INIT

CMake可以根据环境和目标平台例如,xxxFLAGS环境变量的内容将预先准备好,其中xxx将是特定于语言的,但不一定与(例如CXXFLAGS用于CXX,FFLAGS用于Fortran,等等(相同。

另一个解决方案(不是最好的(,因为您已经在修改一些文件,是直接修改flags.make添加include-path,link.txt添加带有-L选项的路径。

我不知道这是否是正确的原因,但显然编译器有一些默认目录,它在其中查找头和库[link]。所以我做了

arm-linux-gnueabihf-gcc -v -x c -E -

我得到了

#include <...> search starts here:
/usr/bin/../lib/gcc/arm-linux-gnueabihf/8.3.0/include
/usr/bin/../lib/gcc/arm-linux-gnueabihf/8.3.0/include-fixed
/usr/bin/../lib/gcc/arm-linux-gnueabihf/8.3.0/../../../../arm-linux-gnueabihf/include
/usr/bin/../arm-linux-gnueabihf/libc/usr/include

然后,我交叉编译并在/usr/arm-linux-gnueabihf中安装boost、flann和Eigen,并在pcl/build文件夹中安装cmake作为

cmake -DCMAKE_C_COMPILER=arm-linux-gnueabihf-gcc 
-DCMAKE_CXX_COMPILER=arm-linux-gnueabihf-g++ 
-DWITH_VTK=OFF 
-DWITH_OPENGL=OFF 
-DCMAKE_PREFIX_PATH=/usr/arm-linux-gnueabihf 
-DCMAKE_INSTALL_PREFIX=/usr/arm-linux-gnueabihf ..

它编译了