在看ch7中遇到了g2o::OptimizableGraph::Vertex::clone() const’未定义的引用的问题。为了方便以后复现,记录如下:
我的环境配置
Pangolin 0.5
Opencv 3.4.16
cere 1.14
g2o 在slambook2的3rdparty中获取的
cmake 3.22.20211211
eigen3.3.7
sophus 0.9.5
//注意不用git clone。直接下载zip压缩包。
//安装流程网上都有,基本上都是CMake工程。
遇到问题:
[ 83%] Linking CXX executable pose_estimation_3d2d
CMakeFiles/pose_estimation_3d2d.dir/pose_estimation_3d2d.cpp.o:(.rodata._ZTVN3g2o10BaseVertexILi6EN6Sophus8SE3GroupIdLi0EEEEE[_ZTVN3g2o10BaseVertexILi6EN6Sophus8SE3GroupIdLi0EEEEE]+0x30):对‘g2o::OptimizableGraph::Vertex::clone() const’未定义的引用
CMakeFiles/pose_estimation_3d2d.dir/pose_estimation_3d2d.cpp.o:(.rodata._ZTV10VertexPose[_ZTV10VertexPose]+0x30):对‘g2o::OptimizableGraph::Vertex::clone() const’未定义的引用
CMakeFiles/pose_estimation_3d2d.dir/pose_estimation_3d2d.cpp.o:(.rodata._ZTVN3g2o8BaseEdgeILi2EN5Eigen6MatrixIdLi2ELi1ELi0ELi2ELi1EEEEE[_ZTVN3g2o8BaseEdgeILi2EN5Eigen6MatrixIdLi2ELi1ELi0ELi2ELi1EEEEE]+0x30):对‘g2o::OptimizableGraph::Edge::clone() const’未定义的引用
CMakeFiles/pose_estimation_3d2d.dir/pose_estimation_3d2d.cpp.o:(.rodata._ZTVN3g2o13BaseUnaryEdgeILi2EN5Eigen6MatrixIdLi2ELi1ELi0ELi2ELi1EEE10VertexPoseEE[_ZTVN3g2o13BaseUnaryEdgeILi2EN5Eigen6MatrixIdLi2ELi1ELi0ELi2ELi1EEE10VertexPoseEE]+0x30):对‘g2o::OptimizableGraph::Edge::clone() const’未定义的引用
CMakeFiles/pose_estimation_3d2d.dir/pose_estimation_3d2d.cpp.o:(.rodata._ZTV14EdgeProjection[_ZTV14EdgeProjection]+0x30):对‘g2o::OptimizableGraph::Edge::clone() const’未定义的引用
collect2: error: ld returned 1 exit status
CMakeFiles/pose_estimation_3d2d.dir/build.make:141: recipe for target 'pose_estimation_3d2d' failed
make[2]: *** [pose_estimation_3d2d] Error 1
CMakeFiles/Makefile2:196: recipe for target 'CMakeFiles/pose_estimation_3d2d.dir/all' failed
make[1]: *** [CMakeFiles/pose_estimation_3d2d.dir/all] Error 2
Makefile:90: recipe for target 'all' failed
make: *** [all] Error 2
具体是什么原因没搞懂,但是估计跟g2o有关,换了很多版本都不行,有可能跟ros的g2o冲突的问题,后面在看了issues后做如下修改:
CMakeLists.txt中
//这里Opencv版本写自己安装的版本,不过这一步好像没有影响,用ros中的opencv是3.3.1,也可以
find_package(OpenCV 3.4.16 REQUIRED)
//第二步 g2o那行换掉,Sophus这里有人遇到fmt的问题,所以我就加上了,不过我去掉了也可以运行
add_executable(pose_estimation_3d2d pose_estimation_3d2d.cpp)
target_link_libraries(pose_estimation_3d2d ${Sophus_LIBRARIES})
target_link_libraries(pose_estimation_3d2d
${G2O_CORE_LIBRARY} ${G2O_STUFF_LIBRARY}
${OpenCV_LIBS})
cmake/FindG2O.cmake中
//加入NO_DEFAULT_PATH
# Find the header files
FIND_PATH(G2O_INCLUDE_DIR g2o/core/base_vertex.h
${G2O_ROOT}/include
$ENV{G2O_ROOT}/include
$ENV{G2O_ROOT}
/usr/local/include
/usr/include
/opt/local/include
/sw/local/include
/sw/include
NO_DEFAULT_PATH
)
# Macro to unify finding both the debug and release versions of the
# libraries; this is adapted from the OpenSceneGraph FIND_LIBRARY
# macro.
MACRO(FIND_G2O_LIBRARY MYLIBRARY MYLIBRARYNAME)
FIND_LIBRARY("${MYLIBRARY}_DEBUG"
NAMES "g2o_${MYLIBRARYNAME}_d"
PATHS
${G2O_ROOT}/lib/Debug
${G2O_ROOT}/lib
$ENV{G2O_ROOT}/lib/Debug
$ENV{G2O_ROOT}/lib
NO_DEFAULT_PATH
)
FIND_LIBRARY("${MYLIBRARY}_DEBUG"
NAMES "g2o_${MYLIBRARYNAME}_d"
PATHS
~/Library/Frameworks
/Library/Frameworks
/usr/local/lib
/usr/local/lib64
/usr/lib
/usr/lib64
/opt/local/lib
/sw/local/lib
/sw/lib
NO_DEFAULT_PATH
)
FIND_LIBRARY(${MYLIBRARY}
NAMES "g2o_${MYLIBRARYNAME}"
PATHS
${G2O_ROOT}/lib/Release
${G2O_ROOT}/lib
$ENV{G2O_ROOT}/lib/Release
$ENV{G2O_ROOT}/lib
NO_DEFAULT_PATH
)
FIND_LIBRARY(${MYLIBRARY}
NAMES "g2o_${MYLIBRARYNAME}"
PATHS
~/Library/Frameworks
/Library/Frameworks
/usr/local/lib
/usr/local/lib64
/usr/lib
/usr/lib64
/opt/local/lib
/sw/local/lib
/sw/lib
NO_DEFAULT_PATH
)
然后在build中cmake和make就可以了。
|