g2o库出现undefined reference to错误
1.我的CMkeLists.txt
cmake_minimum_required(VERSION 2.6) project(g2o_learn) set(CMAKE_CXX_FLAGS "-std=c++11") include_directories("/usr/include/eigen3") find_package(g2o REQUIRED) include_directories(${g2o_INCLUDE_DIRS}) find_package( OpenCV REQUIRED ) include_directories(${OpenCV_INCLUDE_DIRS}) add_executable(g2o_learn main.cpp) target_link_libraries( g2o_learn ${OpenCV_LIBRARIES}) target_link_libraries(g2o_learn ${g2o_LIBRARIES}) install(TARGETS g2o_learn RUNTIME DESTINATION bin)
在这之后,编译程序的时候,出现undefined reference to错误,基本上所有的g2o的模块都找不到,
解决方法如下
1. 找到下载g2o库的文件夹下,进入cmake_modules文件夹下,找到FINDG2O.cmake,然后复制到cpp目录下的cmake文件夹下,然后修改CMakeList.txt文件,修改后的文件内容如下
cmake_minimum_required(VERSION 2.6) project(g2o_learn) set(CMAKE_CXX_FLAGS "-std=c++11") list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) include_directories("/usr/include/eigen3") find_package(g2o REQUIRED) include_directories(${g2o_INCLUDE_DIRS}) find_package( OpenCV REQUIRED ) include_directories(${OpenCV_INCLUDE_DIRS}) add_executable(g2o_learn main.cpp) target_link_libraries( g2o_learn ${OpenCV_LIBRARIES}) #target_link_libraries(g2o_learn ${g2o_LIBRARIES}) target_link_libraries(g2o_learn g2o_core g2o_stuff) install(TARGETS g2o_learn RUNTIME DESTINATION bin)
Thank for your reading !!!
公众号:FPGA之旅