Why incomplete type and forward declaration depending on includes?

asked 2015-02-02 04:47:02 -0600

thdrksdfthmn gravatar image

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)
edit retag flag offensive close merge delete

Comments

1

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.

StevenPuttemans gravatar imageStevenPuttemans ( 2015-02-02 05:00:59 -0600 )edit
1

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?

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-02-02 06:46:15 -0600 )edit
1

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!

StevenPuttemans gravatar imageStevenPuttemans ( 2015-02-02 07:09:36 -0600 )edit