Search code examples
objective-cxcode4opencv

Using OpenCV in Xcode project gives linker errors


After building and installing opencv via their cmake process, I took some suggested steps to integrate the libraries into an Xcode project.

  • I use "Link Binary With Libraries" in Build Phases for both libopencv_core.dylib and libopencv_highgui.dylib
  • "Header Search Paths" contains /usr/local/include/ and /usr/include/ (the opencv headers themselves are in /usr/local/include/opencv2, which I have tried to include)
  • "Library Search Paths" contains /usr/local/lib and /usr/lib (the opencv dylib files are in /usr/local/lib/)

And then I added a bit of demo opencv code. When I run this project, I get errors you'd expect from a linking problem:

Apple Mach-O Linker Error: Undefined symbols for architecture x86_64: "_cvCvtColor", referenced from:

Using file on the dylibs I include shows what I expect:

file /usr/local/lib/libopencv_core.dylib /usr/local/lib/libopencv_core.dylib: Mach-O 64-bit dynamically linked shared library x86_64

file /usr/local/lib/libopencv_highgui.dylib /usr/local/lib/libopencv_highgui.dylib: Mach-O 64-bit dynamically linked shared library x86_64

Both of these files are built for the proper architecture and (I think) properly added to the project. How can I debug other linker issues that I might be having? Where do I go from here?


Solution

  • cvtColor is in libopencv_imgproc.dylib. Add that to the "Link Binary with Libraries" phase and you should be good.