Sophus库是一个较好的李群李代数库,此处安装的是非模板类的Sophus库。具体安装过程如下:
1、安装指令:
git clone https://github.com/strasdat/Sophus.git
cd Sophus/
git checkout a621ff
mkdir build
cd build
cmake ..
make
2、编译过程中出现的问题及解决办法:
问题1:
/Sophus/sophus/so2.cpp:32:26: error: lvalue required as left operand of assignment
unit_complex_.real() = 1.;
/Sophus/sophus/so2.cpp:33:26: error: lvalue required as left operand of assignment
unit_complex_.imag() = 0.;
该错误可以定位到so2.cpp源码文件下:
将
SO2::SO2()
{
unit_complex_.real() = 1.;
unit_complex_.imag() = 0.;
}
修改为
SO2::SO2()
{
//unit_complex_.real() = 1.;
//unit_complex_.imag() = 0.;
unit_complex_.real(1.);
unit_complex_.imag(0.);
}
问题2:
/home/tympn/workspace/slam/practice/Sophus/sophus/so2.cpp:83:67: required from here
/usr/include/eigen3/Eigen/src/Core/AssignEvaluator.h:86:63: ***error: enum constant in boolean context [-Werror=int-in-bool-context]
MayLinearVectorize = bool(MightVectorize) && MayLinearize && DstHasDirectAccess***
这类错误有很多,就不一一列举,只贴其中一条
该错误可以定位到eigen库下的AssignEvaluator.h文件,为了修复gcc7的警告问题,对该文件已做了如下修改:
enum {
DstAlignment = DstEvaluator::Alignment,
SrcAlignment = SrcEvaluator::Alignment,
- DstHasDirectAccess = DstFlags & DirectAccessBit,
+ DstHasDirectAccess = (DstFlags & DirectAccessBit) == DirectAccessBit,
JointAlignment = EIGEN_PLAIN_ENUM_MIN(DstAlignment,SrcAlignment)
};
&& int(OuterStride)!=Dynamic && int(OuterStride)%int(InnerPacketSize)==0
&& (EIGEN_UNALIGNED_VECTORIZE || int(JointAlignment)>=int(InnerRequiredAlignment)),
MayLinearize = bool(StorageOrdersAgree) && (int(DstFlags) & int(SrcFlags) & LinearAccessBit),
- MayLinearVectorize = bool(MightVectorize) && MayLinearize && DstHasDirectAccess
+ MayLinearVectorize = bool(MightVectorize) && bool(MayLinearize) && bool(DstHasDirectAccess)
&& (EIGEN_UNALIGNED_VECTORIZE || (int(DstAlignment)>=int(LinearRequiredAlignment)) || MaxSizeAtCompileTime == Dynamic),
/* If the destination isn't aligned, we have to do runtime checks and we don't unroll,
so it's only good for large enough sizes. */
其中加号行代码替换减号行
参考源:https://bitbucket.org/eigen/eigen/commits/b4f969795d1b0adbb43ebdd8c6bbcb42cb559687?at=3.3
3.使用过程中出现的问题
该库的使用可以安装也可以不安装,这里建议安装,因为只有安装后在阅读源码时才可以跳转到该库的头文件。
不论安不安装,均可以使用下列方式编译调用该库
cmake_minimum_required( VERSION 2.8 )
project( useSophus )
set(CMAKE_BUILD_TYPE "Release")
# 为使用 sophus,您需要使用find_package命令找到它
find_package( Sophus REQUIRED )
include_directories( ${Sophus_INCLUDE_DIRS} )
add_executable( useSophus useSophus.cpp )
target_link_libraries( useSophus ${Sophus_LIBRARIES})
这里有个坑需要注意:
set(CMAKE_BUILD_TYPE "Release")
这条语句不能少,少了后,代码可以正常编译生成可执行文件,但是在运行可执行文件时会出现如下错误:
useSophus: /usr/include/eigen3/Eigen/src/Core/PlainObjectBase.h:285: void Eigen::PlainObjectBase<Derived>::resize(Eigen::Index, Eigen::Index) [with Derived = Eigen::
Matrix<double, 3, 1>; Eigen::Index = long int]: Assertion `(!(RowsAtCompileTime!=Dynamic) || (rows==RowsAtCompileTime)) && (!(ColsAtCompileTime!=Dynamic) || (cols==C
olsAtCompileTime)) && (!(RowsAtCompileTime==Dynamic && MaxRowsAtCompileTime!=Dynamic) || (rows<=MaxRowsAtCompileTime)) && (!(ColsAtCompileTime==Dynamic && MaxColsAtC
ompileTime!=Dynamic) || (cols<=MaxColsAtCompileTime)) && rows>=0 && cols>=0 && "Invalid sizes when resizing a matrix or array."' failed.
Aborted (core dumped)
这是因为该库不支持Debug模式
注意:如果不使用CMAKE_BUILD_TYPE参数,则默认是Debug