一、问题描述
自己在编译Sophus时遇到如下错误:
/home/wong/Datum/third_party/Sophus-1.0.0-template/Sophus-1.0.0/test/core/test_so2.cpp:82:31: error: implicitly-declared ‘Eigen::Map<const Sophus::SO2<double> >::Map(const Eigen::Map<const Sophus::SO2<double> >&)’ is deprecated [-Werror=deprecated-copy] 82 | Eigen::Map<SO2Type const> const_shallow_copy = map_of_const_so2;
二、解决方法
在 CMakeLists.txt 中添加如下语句:
set(CMAKE_CXX_FLAGS "-Wno-error=deprecated-declarations -Wno-deprecated-declarations ")
这里是我添加之后的CMakeLists.txt:
SET(PROJECT_NAME Sophus) PROJECT(${PROJECT_NAME}) CMAKE_MINIMUM_REQUIRED(VERSION 2.8) SET( CMAKE_VERBOSE_MAKEFILE ON) ################################################################################ # Release by default # Turn on Debug with "-DCMAKE_BUILD_TYPE=Debug" IF( NOT CMAKE_BUILD_TYPE ) SET( CMAKE_BUILD_TYPE Release ) ENDIF() set(CMAKE_CXX_STANDARD 14) IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g") SET(CMAKE_CXX_FLAGS_RELEASE "-O3") SET(CMAKE_CXX_FLAGS "-Wall -Werror -Wextra -Wno-deprecated-register -std=c++14 -stdlib=libc++ -Wno-deprecated-register") ELSEIF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g") SET(CMAKE_CXX_FLAGS_RELEASE "-O3") SET(CMAKE_CXX_FLAGS "-Wall -Werror -Wextra -std=c++14 -Wno-deprecated-declarations -ftemplate-backtrace-limit=0") SET(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_DEBUG} --coverage -fno-inline -fno-inline-small-functions -fno-default-inline") SET(CMAKE_EXE_LINKER_FLAGS_COVERAGE "${CMAKE_EXE_LINKER_FLAGS_DEBUG} --coverage") SET(CMAKE_SHARED_LINKER_FLAGS_COVERAGE "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} --coverage") ELSEIF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") ADD_DEFINITIONS("-D _USE_MATH_DEFINES /wd4305 /wd4244") ENDIF() ################################################################################ set(CMAKE_CXX_FLAGS "-Wno-error=deprecated-declarations -Wno-deprecated-declarations ") # 下方省略n行
然后再次编译就可以了!
参考链接:
[1] strasdat. Can’t build #214 [EB/OL]. https://github.com/strasdat/Sophus/issues/214, 2019-07-17/2022-12-06.
[2] cmake 出现大量的警告 deprecated-declarations [EB/OL]. https://www.cnblogs.com/ramlife/p/13740968.html, 2020-09-27/2022-12-06.
[3] Sophus安装踩坑 [EB/OL]. https://blog.csdn.net/weixin_41698305/article/details/116547361, 2021-05-08/2022-12-06.