0

I'm trying compile the simple code with C++ OpenCV but the both compilers g++ and clang++ accuse of undefined reference. I followed this steps for install OpenCV and run the last step (the tests) with success. My System: Ubuntu 18.04

  • The simple code to teste compilation:
#include <opencv2/core.hpp>
int main(){
    cv::Mat image;
}
  • Output for g++ with 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 for clang++ with 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)
  • You forgot to link your code with open cv libs. – cplusplusrat Mar 01 '20 at 02:02
  • How i do this? , i'm user newbie linux –  Mar 01 '20 at 02:05
  • i try this https://stackoverflow.com/questions/24337932/cannot-get-opencv-to-compile-because-of-undefined-references but without success –  Mar 01 '20 at 02:06
  • ok i fixed the problem but i do not know explain the because this fix the problem. i put -lopencv_core in end of command and compiled normally –  Mar 01 '20 at 03:04

0 Answers0