Patricia
Patricia

Reputation: 5089

Cannot build opencv 2.4 on a 64 bit mac for C++ project in Xcode

After looking around a lot and trying every option I found on SO, I'm a little confused about how to get the OpenCV library for architecture x86_64 loaded on my Mac. Here's a little bit of background info:

enter image description here

The first folder contains the Android SDK. The second is the iPhone framework, which uses i386 and armv7 architectures.

Now, I want to create a simple "Hello World" C++ application in Xcode which needs the correct library for x86_64 architecture.

I've looked at this tutorial as well as others' posted steps as follows:

With all version (except OpenCV-2.4.6.1), the process fails at "make -j8". I get the same error every time:

Linking CXX shared library ../../lib/libopencv_core.dylib

Undefined symbols for architecture x86_64:

  "___sincos_stret", referenced from:

      cv::RotatedRect::points(cv::Point_<float>*) const in matrix.cpp.o

      cv::RotatedRect::boundingRect() const in matrix.cpp.o

ld: symbol(s) not found for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)

make[2]: *** [lib/libopencv_core.2.4.3.dylib] Error 1

make[1]: *** [modules/core/CMakeFiles/opencv_core.dir/all] Error 2

make[1]: *** Waiting for unfinished jobs....

[ 28%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfThreading.cpp.o

[ 28%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfTileDescriptionAttribute.cpp.o

[ 28%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfTiledInputFile.cpp.o

[ 29%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfTiledMisc.cpp.o

[ 29%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfTiledOutputFile.cpp.o

[ 29%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfTiledRgbaFile.cpp.o

[ 29%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfTileOffsets.cpp.o

[ 29%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfTimeCode.cpp.o

[ 29%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfTimeCodeAttribute.cpp.o

[ 29%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfVecAttribute.cpp.o

[ 29%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfVersion.cpp.o

[ 29%] [ 30%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfWav.cpp.o

Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfZipCompressor.cpp.o

Linking CXX static library ../lib/libIlmImf.a

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../lib/libIlmImf.a(IlmThread.cpp.o) has no symbols

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../lib/libIlmImf.a(IlmThreadMutex.cpp.o) has no symbols

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../lib/libIlmImf.a(IlmThreadSemaphore.cpp.o) has no symbols

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../lib/libIlmImf.a(IlmThreadSemaphorePosixCompat.cpp.o) has no symbols

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../lib/libIlmImf.a(IlmThread.cpp.o) has no symbols

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../lib/libIlmImf.a(IlmThreadMutex.cpp.o) has no symbols

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../lib/libIlmImf.a(IlmThreadSemaphore.cpp.o) has no symbols

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../lib/libIlmImf.a(IlmThreadSemaphorePosixCompat.cpp.o) has no symbols

[ 30%] Built target IlmImf

make: *** [all] Error 2

pdls-mbp:build pdl$ 

With OpenCV-2.4.6.1, the process fails at "sudo make install" and I get the following error:

Linking CXX shared library ../../lib/libopencv_core.dylib

Undefined symbols for architecture x86_64:

  "___sincos_stret", referenced from:

      cv::RotatedRect::points(cv::Point_<float>*) const in matrix.cpp.o

      cv::RotatedRect::boundingRect() const in matrix.cpp.o

ld: symbol(s) not found for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)

make[2]: *** [lib/libopencv_core.2.4.6.dylib] Error 1

make[1]: *** [modules/core/CMakeFiles/opencv_core.dir/all] Error 2

make: *** [all] Error 2

Lucys-MacBook-Pro:build pdl$ 

When I installed OpenCV using Homebrew, opencv was installed in use/local/opt/opencv and I can see all of the dylib files under the lib folder:

Contents of lib folder

All of this completely confuses me, because I think all I need is a .a library file, no?

I have found the dylib files that were installed with HomeBrew in /usr/local/Cellar/opencv/2.4.6.1/lib but when I try to choose frameworks and libraries to add, they do not show up in the list. Instead, this is all I see:

Choose frameworks and libraries to add:

Aldo, been following this MacPorts tutorial.

Upvotes: 0

Views: 3884

Answers (1)

trojanfoe
trojanfoe

Reputation: 122381

Have you considered using macports? It has opencv 2.4.8 available.

So after installing macports, all that nonsense you've been through, is reduced to:

$ sudo port selfupdate
$ sudo port install opencv

if you want a variant or two, for example OpenCL and Python support, then that would be:

$ sudo port install opencv +opencl +python27

and the binaries/libraries/whatever will be installed into /opt/local/....

Upvotes: 2

Related Questions