1

(I am new at pretty much everything that I will discuss here... apologies if the question is very basic) - I used Xcode to write some C++ code using OpenCV (dynamic libraries). The algorithm runs smoothly and I created an executable file that also works. However, it only works in my computer.

I understand that I need to use static libraries instead of dynamic libraries. I have done some research and found how to do this here: http://www.shiffman.net/2011/01/23/how-to-build-opencv-static-libraries-mac-os-x/ and here: http://www.randomsequence.com/articles/opencv-snow-leopard/.

I have followed the steps and, although I had to make a couple of changes, I was able to build ".a" files such as "libopencv_highgui.a".

My code, however, doesn't work anymore when I replace the libraries. I get 200+ errors. This is one of them:

Undefined symbols for architecture x86_64: "_gzputs", referenced from: __ZL7icvPutsP13CvFileStoragePKc in libopencv_core.a(persistence.o)

I have searched for this question here but this is the closest I could find: Linking OpenCV libraries in Xcode (not exactly the same question).

Thanks everyone!

Community
  • 1
  • 1
lino
  • 13
  • 1
  • 3

1 Answers1

2

You need .a files from $OPENCV_BUILD_PATH/3rdparty/lib/.

The _gzputs from your question belongs to libzlib.a


To link with OpenCV static libraries you also need to add all OpenCV's dependencies to you application. The most of these dependencies comes from the opencv_highui module and the list of dependencies is dependent from your build configuration so I can't tell you the full list. But you can find it yourself: open the CMakeCache.txt from your OpenCV build directory with any text editor and search for opencv_highgui_LIB_DEPENDS line. You need all items from that line except the word general.

Andrey Kamaev
  • 29,582
  • 6
  • 94
  • 88
  • Thanks! This helped me a lot. Now I only get 25% of the errors. I think I still need to do something about the libopencv_highgui.a: `Undefined symbols for architecture i386: "_objc_msgSend", referenced from: _cvInitSystem in libopencv_highgui.a(window_cocoa.o) -[CVWindow cvMouseEvent:] in libopencv_highgui.a(window_cocoa.o) -[CVWindow rightMouseDragged:] in libopencv_highgui.a(window_cocoa.o)` – lino Jun 21 '12 at 21:17
  • @lino I've updated the answer. You need to link with all frameworks/libs used by OpenCV because dependencies from static libraries are not inherited automatically. – Andrey Kamaev Jun 22 '12 at 21:09