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/– pic