vslam14讲中编译G2O报错: 对‘google::LogMessageFatal::LogMessageFatal(xxxxx)’未定义的引用; GFLAGS报错

我遇到的问题就是在编译第六章第三个例子的时候,按照它的cmakelist写好了。但是一去编译发现自己就会出现如下的错误:
vslam14讲中编译G2O报错: 对‘google::LogMessageFatal::LogMessageFatal(xxxxx)’未定义的引用; GFLAGS报错_第1张图片
不要慌,试试下面我这种解决方案:

首先重新下载和编译 gflags 和 glog 两个库,放心速度很快:

1. gflags

    git clone https://github.com/gflags/gflags.git
    cd gflags
    mkdir build && cd build
    cmake -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_SHARED_LIBS=ON -DGFLAGS_NAMESPACE=gflags ../ 
    make -j4
    sudo make install

2. glog

git clone https://github.com/google/glog
cd glog/cmake/
cmake ..
sudo make install

到这里应该没什么问题,毕竟是两个简单的库,接下来,一定要改一下你的CMakeLists,添加如下的语句:

  1. 一个find_package
  2. 一个target_link_libraries

这下面是我的实例,注意我只是把重要的截出来了,供你参考理解:


find_package (glog 0.6.0 REQUIRED)
set(CMAKE_CXX_FLAGS "-std=c++14 ")
target_link_libraries(g2oCurveFitting ${OpenCV_LIBS} glog::glog  ${G2O_LIBS}
						${G2O_CORE_LIBRARY} ${G2O_STUFF_LIBRARY})

完整的CMakeLists.txt

cmake_minimum_required(VERSION 3.17)
project(g2oCurveFitting)

set(OpenCV "/usr/local/share/OpenCV")
find_package(OpenCV 3.4.15 REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})

LIST(APPEND CMAKE_MODULE_PATH /home/gl/gitrepo/g2o/cmake_modules)
SET(G2O_ROOT /home/gl/gitrepo/g2o)

FIND_PACKAGE(G2O REQUIRED)
find_package (glog 0.6.0 REQUIRED)
include_directories(${G2O_INCLUDE_DIRS})
include_directories("/usr/local/share/OpenCV")

set(CMAKE_CXX_FLAGS "-std=c++14 ")

add_executable(g2oCurveFitting g2oCurveFitting.cpp)
target_link_libraries(g2oCurveFitting ${OpenCV_LIBS} glog::glog  ${G2O_LIBS}${G2O_CORE_LIBRARY} ${G2O_STUFF_LIBRARY})

你可能感兴趣的:(VSLAM)