合項目分支代碼的時候,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忽略這個警告。