环境
系统 | Ubuntu18.04 |
---|---|
Host架构 | x86 |
Target架构 | ARMv8 64bit |
PCL版本 | 1.9.0 |
Boost版本 | 1.68.0 |
Eigen版本 | 3.4.0 |
Flann版本 | 1.9.2 |
Lz4版本 | 1.9.4 |
任务需求:在x86架构的Ubuntu18.04的虚拟机中交叉编译PCL源码,以能在ARMv8 64位系统上运行。
1、下载以上对应版本的源码,并解压
2、在解压后的pcl-1.9.0目录中新建build目录
3、打开Cmake,按下图根据自己的需求配置交叉编译选项,因为我没有显示需求,所以不需要OpenGL和VTK
4、其他的部分都比较顺利,主要问题出在Boost库上,因为PCL需要Boost,cmake时会提示无法找到Boost的错误,修改pcl工程下的文件,如图所示
在pcl_find_boost.cmake文件开头加入以下内容,并保存
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC OFF)
add_definitions(-DBoost_USE_STATIC_LIBS=ON)
set(Boost_INCLUDE_DIR /usr/local/include/)
set(Boost_LIBRARY_DIR /usr/local/lib/)
5、第三方库重点是Boost库的编译,流程如下
- 执行./bootstrap.sh文件
./bootstrap.sh --with-libraries=system,filesystem,thread,date_time,iostreams --with-toolset=gcc #system,filesystem,thread,date_time,iostreams这些库是PCL所必须的,根据需求填写
- 修改project-config.jam文件
将原有的改为(根据自己的交叉编译工具路径来定)
using gcc : arm : /usr/bin/aarch64-linux-gnu-gcc ;
- 修改gcc.jam文件
增加如下一行:
compile-link-flags <link>static/<target-os>$(non-windows) : -fPIC ;
此步骤的主要目的是打开-fPIC,避免PCL在编译时找不到boost库的.a文件
- 进行编译并安装boost
sudo ./b2 cxxflags=-fPIC cflags=-fPIC -a install
6、PCL在编译中的Eigen错误解决
如果出现以下错误的话:
应修改文件:
按如下方式替换:
/*
Eigen::Vector3f view = camera_pose_.block (0, 0, 3, 1); // view vector for the camera - first column of the rotation matrix
Eigen::Vector3f up = camera_pose_.block (0, 1, 3, 1); // up vector for the camera - second column of the rotation matrix
Eigen::Vector3f right = camera_pose_.block (0, 2, 3, 1); // right vector for the camera - third column of the rotation matrix
Eigen::Vector3f T = camera_pose_.block (0, 3, 3, 1); // The (X, Y, Z) position of the camera w.r.t origin
*/
Eigen::Vector3f view = camera_pose_.block<3, 1> (0, 0); // view vector for the camera - first column of the rotation matrix
Eigen::Vector3f up = camera_pose_.block<3, 1> (0, 1); // up vector for the camera - second column of the rotation matrix
Eigen::Vector3f right = camera_pose_.block<3, 1> (0, 2); // right vector for the camera - third column of the rotation matrix
Eigen::Vector3f T = camera_pose_.block<3, 1> (0, 3); // The (X, Y, Z) position of the camera w.r.t origin
/*
pl_f.block (0, 0, 3, 1).matrix () = (fp_bl - fp_br).cross (fp_tr - fp_br); // Far plane equation - cross product of the
pl_f (3) = -fp_c.dot (pl_f.block (0, 0, 3, 1)); // perpendicular edges of the far plane
pl_n.block (0, 0, 3, 1).matrix () = (np_tr - np_br).cross (np_bl - np_br); // Near plane equation - cross product of the
pl_n (3) = -np_c.dot (pl_n.block (0, 0, 3, 1)); // perpendicular edges of the far plane
*/
pl_f.block<3, 1> (0, 0).matrix () = (fp_bl - fp_br).cross (fp_tr - fp_br); // Far plane equation - cross product of the
pl_f (3) = -fp_c.dot (pl_f.block<3, 1> (0, 0)); // perpendicular edges of the far plane
pl_n.block<3, 1> (0, 0).matrix () = (np_tr - np_br).cross (np_bl - np_br); // Near plane equation - cross product of the
pl_n (3) = -np_c.dot (pl_n.block<3, 1> (0, 0)); // perpendicular edges of the far plane
/*
pl_r.block (0, 0, 3, 1).matrix () = b.cross (c);
pl_l.block (0, 0, 3, 1).matrix () = d.cross (a);
pl_t.block (0, 0, 3, 1).matrix () = c.cross (d);
pl_b.block (0, 0, 3, 1).matrix () = a.cross (b);
pl_r (3) = -T.dot (pl_r.block (0, 0, 3, 1));
pl_l (3) = -T.dot (pl_l.block (0, 0, 3, 1));
pl_t (3) = -T.dot (pl_t.block (0, 0, 3, 1));
pl_b (3) = -T.dot (pl_b.block (0, 0, 3, 1));
*/
pl_r.block<3, 1> (0, 0).matrix () = b.cross (c);
pl_l.block<3, 1> (0, 0).matrix () = d.cross (a);
pl_t.block<3, 1> (0, 0).matrix () = c.cross (d);
pl_b.block<3, 1> (0, 0).matrix () = a.cross (b);
pl_r (3) = -T.dot (pl_r.block<3, 1> (0, 0));
pl_l (3) = -T.dot (pl_l.block<3, 1> (0, 0));
pl_t (3) = -T.dot (pl_t.block<3, 1> (0, 0));
pl_b (3) = -T.dot (pl_b.block<3, 1> (0, 0));
7、编译过程中的Lz4库的错误
在如图所示目录下打开link.txt,加入 -llz4
8、根据电脑内存情况来
执行make -j2
,直到编译完成