Home>

g ++ -o test hahu.cpp $(pkg-config --cflags --libs opencv4)
When I compiled it with, I got the following error. I searched, but I don't know the solution.
If anyone can understand it, please let me know.

The code is also below.
I have opencv installed with brew.

#include<iostream>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc.hpp>
#pragma comment (lib, "opencv_world300d.lib")
int main (int argc, const char * argv [])
{
   int hr = -1;
   try
   {
      cv :: Mat src, edge, dst;
      std :: vector<cv :: Vec4i>lines;
      // Image loading
      src = cv :: imread ("D: /TEMP/MaverickProj/Image/OpenCV/45/building.jpg", cv :: IMREAD_GRAYSCALE);
      cv :: namedWindow ("src", 1);
      imshow ("src", src);
      // Contour extraction
      cv :: Canny (src, edge, 50, 200, 3);
      // Secure image area
      dst = cv :: Mat :: zeros (src.rows, src.cols, CV_8UC3);
      // src [0]->dst [2], src [0]->dst [1], src [0]->dst [0]
      // Specify the copy source index and copy destination index as if
      int fromTo [] = {0, 2, 0, 1, 0, 0};
      // Increase the single channel to 3 channels and copy
      cv :: mixChannels (&src, 1,&dst, 1, fromTo, 3);
      // Line segment detection
      cv :: HoughLinesP (
         edge, // 8-bit, single-channel binary input image. This image may be rewritten by a function.
         lines, // Vector that outputs the detected line segment
         1, // Distance resolution in pixels.
         CV_PI/180.0, // Angular resolution in radians
         80, // Only straight lines that sufficiently exceed the threshold .threshold are output targets.
         30, // Minimum line segment length
         10 // Maximum distance allowed if two points are considered to be on the same line segment
         );
      // Line segment drawing
      for (auto line: lines)
      {
         cv :: line (dst, cv :: Point (line [0], line [1]), cv :: Point (line [2], line [3]), cv :: Scalar (0, 0, 255) , 1);
      }
      cv :: namedWindow ("dst", 1);
      cv :: imshow ("dst", dst);
      cv :: waitKey (0);
      hr = 0;
   }
   catch (cv :: Exception ex)
   {
      std :: cout<<ex.err<<std :: endl;
   }
   // Discard the window
   cv :: destroyAllWindows ();
   return hr;
}
Undefined symbols for architecture x86_64:
  "__ZN2cv11namedWindowERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEi", referenced from:
      _main in ccLV9OlL.o
  "__ZN2cv6imreadERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEi", referenced from:
      _main in ccLV9OlL.o
  "__ZN2cv6imshowERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_11_InputArrayE", referenced from:
      _main in ccLV9OlL.o
ld: symbol (s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
  • Answer # 1

    It was an error that occurred a long time ago when I changed from standard clang to gcc.
    Since gcc g ++ in/usr/local/bin was working with priority, I resolved this symbolic link and compiled it so that standard clang g ++ in/usr/bin was prioritized. Has been activated. Probably due to a bug in opencv4 and g ++ (gcc).
    Compile g ++ hahu.cpp -std = c ++ 11pkg-config --cflags --libs opencv4-o sample
    I did it at.

  • Answer # 2

    The symptom looks like an error caused by trying to link different versions of OpenCV libraries.
    For now, try uninstalling and reinstalling everything you can think of.
    I don't have a Mac, so I'm not sure how to find it.