1

For my application running on iPhone I am using OpenCV using opencv2.framework in Xcode with objective-c and C++ as languages. My development worked well until I wanted to introduce cv::Tracker that is not included in opencv2.framework but part of opencv_contrib.

  1. I rebuilt and installed from the source opencv-3.4.0 with opencv_contrib-master using CMake and terminal commands make and install.

  2. In Xcode I have set HEADER_SEARCH_PATHS = /usr/local/include and LIBRARY_SEARCH_PATHS = /usr/local/lib

When compiling I get a long list of errors of the style:

Undefined symbols for architecture x86_64:
"cv::error(int, cv::String const&, char const*, char const*, int)", 
referenced from:
cv::Mat::Mat(int, int, int, void*, unsigned long) in OpenCVRenderer.o
"cv::Mat::operator=(cv::Scalar_<double> const&)", referenced from:
cv::Mat::Mat(int, int, int, cv::Scalar_<double> const&) in 
OpenCVRenderer.o
cv::Mat::Mat(cv::Size_<int>, int, cv::Scalar_<double> const&) in 
OpenCVRenderer.o
"cv::Mat::deallocate()", referenced from:
cv::Mat::release() in OpenCVRenderer.o
"cv::polylines(cv::_InputOutputArray const&, cv::_InputArray const&, 
bool, cv::Scalar_<double> const&, int, int, int)", referenced from:
.
.
.

I set OTHER_LDFLAGS = (list of opencv dylibs) preceeded by a "-" sign

Now I get errors as if the libraries are not found while there are in fact in /usr/local/lib

For example I get:

ld: library not found for -libopencv_core.3.4.0.dylib
clang: error: linker command failed with exit code 1 (use -v to see 
invocation)

Any help? Thank you.

  • Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) –  Feb 04 '18 at 10:19
  • I think it would help if you could say exactly what you put for OTHER_LDFLAGS instead of just describing it. – john Feb 04 '18 at 10:27
  • @john:OTHER_LFLAGS = -libopencv_core.3.4.0.dylib -libopencv_highgui.3.4.0.dylib -libopencv_imgproc.3.4.0.dylib -libopencv_tracking.3.4.0.dylib -libopencv_video.3.4.0.dylib – Brian Scherady Feb 04 '18 at 11:37
  • @BrianScherady I'm not an expert on the iPhone but if it's anything like other linux environments I would try -lopencv_core.3.4.0 -lopencv_highgui.3.4.0 etc. etc. When linking with a library you normally have -l followed by the library name but you omit the 'lib' prefix and the extension (.dylib, .so or .a) from the library name. – john Feb 04 '18 at 14:26
  • @john: adding the extension .dylib, at the end of library names, does not help :( – Brian Scherady Feb 04 '18 at 17:03
  • @BrianScherady Errm, I said remove the dylib extension – john Feb 04 '18 at 19:52

1 Answers1

0

There are a couples of problems with your settings.

  1. You only specified where to find the libraries, not opencv2.framework. You should either specify framework_search_path (and link your framework to the project) or link the corresponding libraries.

  2. You said you were building an iPhone app, yet the error says Undefined symbols for architecture x86_64:. That is, either you built your app for phone simulator or for mac. Yet, your framework is most likely built for iPhone architecture (armv7 and arm64). This case, you need to rebuild the framework. If you build iPhone app, do not link any dylib libraries in /usr/local/lib/.

Note that libopencv_core.3.4.0.dylib is part of normal opencv so the error has nothing to do with opencv_contrib (yet).

Quang Hoang
  • 146,074
  • 10
  • 56
  • 74