Why incomplete type and forward declaration depending on includes?
I have seen that if I do:
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
I am getting some errors:
/usr/local/include/opencv2/core/mat.hpp:58:28: error: invalid use of incomplete type ‘class cv::Mat’
inline void Mat::initEmpty()
^
/usr/local/include/opencv2/core/base.hpp:526:18: error: forward declaration of ‘class cv::Mat’
class CV_EXPORTS Mat;
^
....
And if I change the includes to:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
all the errors (much more than the two mentionned) disappear. I am using OpenCV 2.4 on Ubuntu 14.
Could it be because of the linking? I use CMake and it looks like this:
#...
find_package(OpenCV REQUIRED COMPONENTS
core
highgui
imgproc
)
#...
include_directories(
${OpenCV2_INCLUDE_DIRS}
#...
)
#...
target_link_libraries(${EXECUTABLE_NAME}
${OpenCV_LIBS}
#...
)
install(TARGETS ${EXECUTABLE_NAME} RUNTIME DESTINATION bin)
Simply said, the first includes is the way you should work for OpenCV3.0, the second for 2.4. There has been a merge down of those 3.0 headers for buildbot purposes, but they are known to cause problems.
in other words:
#include <opencv2/core.hpp>
is for OpenCV 3 and#include <opencv2/core/core.hpp>
is for OpenCV 2.4? And in this case I shall change everything to the second form, until OpenCV 3?Yes, as it has been all along. In OpenCV3.0 the headers moved up 1 level. So changing it all back to include the subfolders should indeed do the trick!