解决deprecated-declarations的正确的做法

合项目分支代码的时候,cmake出现大量的警告 deprecated-declarations,于是我按照网上的教程改了CMakeLists.txt,增加下面的属性

set(CMAKE_CXX_FLAGS "-Wno-error=deprecated-declarations -Wno-deprecated-declarations ")

结果导致项目中出现大量的cv找不到。
这里项目中CMakeLists.txt关于opencv

##OpenCV
if(WITH_OPENCV)
  set(OpenCV_FIND_QUIETLY true)
  #find_package(OpenCV REQUIRED) //this will include opencv_ts which result in crash on centos
  find_package(OpenCV OPTIONAL_COMPONENTS imgcodecs)
  set(imgcodecs_libs ${OpenCV_LIBS})
  find_package(OpenCV REQUIRED core imgproc highgui features2d)
  if(OpenCV_FOUND)
    if(imgcodecs_FOUND)
      list(APPEND OpenCV_LIBS imgcodecs_libs)
    endif()
    message(STATUS "HAVE_OPENCV enabled")
    message(STATUS "opencv libraries: ${OpenCV_LIBS}")
    set(HAVE_OPENCV true)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_OPENCV")
  else()
    set (HAVE_OPENCV false)
  endif()
else()
  set (HAVE_OPENCV false)
endif()
#ifdef HAVE_OPENCV
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#if (CV_MAJOR_VERSION >= 3)
#include "opencv2/imgcodecs/imgcodecs.hpp"
#endif
#endif

之前的是正确的其实是正确的。

我增加那条属性是干什么

因为项目中之前有些函数,马上就要因为版本更新不使用了,于是在该函数加上attribute_deprecated 这个属性。
所以出现deprecated-declarations警告

正确的解决方案

之前的函数要弃用,别人已经通过attribute_deprecated告诉我们了。所以我们新的代码就要更新,而不是在CMakeLists.txt忽略这个警告。

posted @ 2021-03-08 17:52  cyssmile  阅读(7447)  评论(0编辑  收藏  举报