Opencv build does not find include

Asked

Viewed 38 times

1

I’m trying to compile a simple code just to test but when I compile with both g++ and Clang++ they say that the reference to the method was not found. I followed the steps of this official Opencv installation guide, everything went well and I still ran the test step successfully. I’m using Ubuntu 18.04

  • Simple code just to try to compile
#include <opencv2/core.hpp>
int main(){
    cv::Mat image;
}
  • g++ output with the command g++ teste.cpp -o teste -I /usr/local/include/opencv4 :
/tmp/ccqJeAzC.o: In function `cv::Mat::~Mat()':
teste.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to `cv::fastFree(void*)'
/tmp/ccqJeAzC.o: In function `cv::Mat::release()':
teste.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x4b): undefined reference to `cv::Mat::deallocate()'
collect2: error: ld returned 1 exit status
  • Output to the Clang used the command clang++ teste.cpp -o teste -I /usr/local/include/opencv4 :
/tmp/teste-44c531.o: In function `cv::Mat::~Mat()':
teste.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD2Ev]+0x47): undefined reference to `cv::fastFree(void*)'
/tmp/teste-44c531.o: In function `cv::Mat::release()':
teste.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x48): undefined reference to `cv::Mat::deallocate()'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
  • Well I was able to fix but I don’t know why it fixes my problem. I just put the following at the end of the command -lopencv_core found this here https://answers.opencv.org/question/221603/undefined-reference-to-imread/

1 answer

1


You are not linking a necessary library, in this case, as you yourself solved, opencv_core.

The -lopencv_core flag is passed to Linker to look for the static library libopencv_core. a or by the dynamic library libopencv_core.so in its standard directories (and in the directories indicated with the -L flag) and then make the link to the found file.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.