Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

installed Opencv 4 from source, C++ headers not linked correctly

I jusst installed Opencv 4.1.1 from source, with python 3 bindings. My Python installation seems to work correctly, because if I run:

import cv2
cv2.__version__

I get '4.1.1'

However, I also want to use some C++ code. I had a previous installation of 3.4.3 that I built from source, and unfortunately I had deleted the build folder before uninstalling it. So, when I run this C++ code:

#include <opencv4/opencv2/core.hpp>

using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
    //print opencv version
    printf("opencv version: %d.%d.%d\n",CV_VERSION_MAJOR,CV_VERSION_MINOR,CV_VERSION_REVISION);

    return 0;
}

When i compile with this command :

g++ -o get_version get_version.cpp -I/usr/local/include/opencv4/opencv2 -Lusr/local/lib -lopencv_core

It returned 3.4.3.

So, I wanted to fix this, so I found the old header files, and deleted them all (they were located in /usr/local/include/opencv2). But now when I try to compile my code, it gives me the error:

In file included from get_version.cpp:1:0:
/usr/local/include/opencv4/opencv2/core.hpp:52:10: fatal error: opencv2/core/cvdef.h: No such file or directory
 #include "opencv2/core/cvdef.h"
          ^~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

But, if I navigate to /usr/local/include/opencv4/opencv2/core/, I can see the file, cvdef.h, so I don't know why the compiler can't find it.

So, why are my headers not linking correctly? And how can I fix this. I'm used to Python, so I'm I'm not used to having to deal with linking all these header files, so sorry if it's something obvious.