Linking with OpenCV in XCode

I'm trying to link in the OpenCV library with my XCode project, and I'm not having much luck. I installed OpenCV in /usr/local using their configure/make/sudo make install approach; the following files are now in usr/local/lib:

libhighgui.2.0.0.dylib
libhighgui.2.dylib
libhighgui.dylib
libhighgui.la
libcv.2.0.0.dylib
libcv.2.dylib
libcv.dylib
libcv.la
libcxcore.2.0.0.dylib
libcxcore.2.dylib
libcxcore.dylib
libcxcore.la

I tried dragging some of these into the XCode project, but it didn't change any of the linker errors.

Let me say----I'm not a big fan of XCode's approach to library specification (drag and drop something into the project). That's a useful feature, but there really needs to be a good old g++ style "input libraries" setting somewhere. I tried to use the Other Linker Flags field:

-lcv -lcxcore -lhighgui

but that didn't seem to help.

I'm aware that there's a prebuilt OpenCV Private Framework:
http://opencv.willowgarage.com/wiki/MacOS_X_OpenCVPort
but as I understand it, a private framework doesn't help at all with a C++ Command-Line Tool.

The errors I'm getting are all of the form:
Line Location Tool:0: "_cvLoadImage", referenced from:
Line Location Tool:0: "_cvGetSize", referenced from:
Line Location Tool:0: "_cvGet2D", referenced from:
etc. Note that the places they're referenced from are not sequentially given after these lines....they're all clumped together at the top. XCode bug I bet.

Here's the really curious part. When I build in Debug configuration, everything works fine---the program runs as expected, no difficulties. Only in the Release configuration does this occur. I really want to test my program optimized, however.....

Frankly at this point, I'm considering just building with g++. I think it might be less frustrating.

MacBook Pro, Mac OS X (10.5.6), .

Posted on May 3, 2009 4:30 PM

Reply
7 replies

May 3, 2009 6:50 PM in response to LindleyF

Debug and Release build settings are independent. For example in Debug, projects usually want to link with libraries that include symbols; otherwise not. So it's common for Debug to use a set of lib paths that are different from Release. Adding a framework to a project may add several paths for xCode to choose from based on config., SDK version, and target platform.

I'm not clear on exactly where or how you added your libs to the project (there are other ways besides dragging, btw), but since you knew how to do that for the Debug config., just do it again for Release. Xcode won't care that the paths are the same, they just need to be set separately.

If you'd rather use gcc from the Terminal command line, that will work just fine too. I do lots of my work that way. In fact you can still use the Xcode editor by typing "open file_name.C" at the command line.

May 3, 2009 8:00 PM in response to RayNewbie

I didn't have to do anything to get it working in the Debug configuration---since it uses ZeroLink and /usr/local/lib is automatically in the PATH, it "just worked". Whereas Release actually needed something substantial to link against.

I finally did figure out a way to get it working. I used the aforementioned Private Framework. Now, that's not a permanent solution for a C++ Command-Line tool since there's no application package....but so long as the Framework folder is put in the correct relative position to the executable (../Frameworks/OpenCV.framework), everything works out. Should be good enough for the moment.

If there's a better way I'd still like to hear about it.

Jun 25, 2009 4:18 PM in response to LindleyF

Hey

I too am facing same issues with linking opencv. My debug config seems to be workign just fine but Release has linking errors. I have added Lib search paths, Header search path and all the libs in -l<style> in other library flags.

I am currently suing Eclipse which is able to link fairly well. I am new to Mac and would like to experience Xcode, in case someone figure out solution please let me know.

Dec 15, 2009 7:31 AM in response to artware

I tried to build this library myself, but it fails because I don't have QT. I even tried turning off QT support without success.

As I have definitively problem this package isn't put together very well, there are no guarantees.

Are you able to get FaceTracker to build correctly in both debug and release? If so, you may want to compare settings from the target panes. That might be where the difference is. You can also check the raw output from FaceTracker.

Dec 15, 2009 8:22 AM in response to etresoft

FaceTracker builds (and works) fine - both debug and release versions, using the prebuilt 1.2 framework, with no problems of any kind. I gave up (for now) trying to build the 2.0 framework myself as there were just too many issues, so am using the framework.

I have spent hours comparing build settings on my project(s) and have had no love. Here is the history, after making FaceTracker work.

I built a project to put this into a Quartz plug-in. First problem was getting it to simply compile - with the same includes, paths, etc as FaceTracker there were many unfound includes. Resolved the framework stuff eventually by NOT using System/Library/Private Frameworks/ - just put it in user space at /Library/Frameworks/. Never resolved finding <cassert> and <stdio> - but not actually needed, so punted on those.

Got it to compile with minimal warnings, but BAM, won't link! Cannot find any of the functions in OpenCV. Spent more hours looking at framework paths, compiler settings, link setting, build configs ... nothing changed for the better.

Finally built a little project to simply evaluate the include and link stuff. Got it to compile, and slowly added more references found only in the OpenCV headers, at multiple layers in the header structure. All good. Added one function call, that compiles and links in FaceTracker, and same result - cannot find the link symbol for "_cvLoad", a helper function contained in the framework.

I am sure this is a build problem - the wrong symbol stripping or a funny sequence of linkage paths and flags. I am just hoping someone out there has had to deal with this with open source ports, or this library ...

I am new to XCode, and have not worked the Unix/linux world in a looong time. BTW, using 10.6 sdk - the framework uses 10.4. I haven't installed 10.4 yet, and that is my next approach.

Any ideas?

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Linking with OpenCV in XCode

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.