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

时间:2020-11-09 10:23:02

标签: c++ boost arm g++ point-cloud-library


修改

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


我想交叉编译Raspberry 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/

然后我从here下载带有硬浮点(arm-linux-gnueabihf)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来指定以前安装的所有: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

对我所缺少的东西有任何想法吗?谢谢!

更新

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

有关

2 个答案:

答案 0 :(得分:0)

如果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将是特定于语言的,但不一定与(例如CXX的CXXFLAGS,Fortran的FFLAGS等)相同。

另一个解决方案(不是最好的),因为您已经在修改某些文件,所以直接修改flags.make以添加包含路径,并使用-L选项添加link.txt以添加路径。

答案 1 :(得分:0)

我不知道这是否是正确的原因,但是显然编译器有一些默认目录,用于查找标头和库 [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 ..

并编译