OpenCV2.3.1, Mac OS X 10.7.1 (Lion), Xcode 4 and Cmake 2.8

Discussion in 'Mac Programming' started by kmoria, Sep 20, 2011.

  1. kmoria macrumors newbie

    kmoria

    Joined:
    Sep 20, 2011
    Location:
    Victoria Canada
    #1
    Hi,
    I am new to Mac and I am trying to install OpenCV 2.3.1 Using CMake 2.8.

    I installed CMake, in the source code I located the folder which is in "/Users/ka_moria/Documents/OpenCV-2.3.1"

    Binaries in :/Users/ka_moria/Documents/cmake_binary_dir

    I clicked on configure and then generate.

    I open the Xcode4, followed the instructions in the thread:
    http://forums.macrumors.com/showthread.php?t=1145869

    and I am stuck in point 14 , I cant find "libopencv_*.dylib files ".
    I also looked for user/local to check the files but there were no folder called local, does that means OpenCv is not installed?
     
  2. Mac Player macrumors regular

    Joined:
    Jan 19, 2006
  3. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #3
    You've only generated the either the makefiles. You need to go on to actually build the library. Follow the instructions under the heading "Compile using GCC from command line" in the the Install Guide.

    Then you should find you have the .dylib files under the lib directory of cmake_binary_dir and the .h files under the include directory of cmake_binary_dir.
     
  4. lou.salome macrumors newbie

    Joined:
    Jan 4, 2012
    Location:
    California & London UK
    #4
    Xcode 4, OpenCV

    Hello there,

    I am trying to build a project in Xcode 4 using OpenCV, and I am getting the following error (scroll down for the red and bold text):


    Ld /Users/AOA/Library/Developer/Xcode/DerivedData/wanesbbOpenCV-fayzvmciykwswxbvwtyujutmkjgz/Build/Products/Debug/wanesbbOpenCV normal x86_64
    cd "/Users/AOA/Documents/Xcode Projects/wanesbbOpenCV"
    setenv MACOSX_DEPLOYMENT_TARGET 10.7
    /Developer/usr/bin/llvm-g++-4.2 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.7.sdk -L/Users/AOA/Library/Developer/Xcode/DerivedData/wanesbbOpenCV-fayzvmciykwswxbvwtyujutmkjgz/Build/Products/Debug -L/usr/local/Cellar/opencv/2.3.1a/lib -F/Users/AOA/Library/Developer/Xcode/DerivedData/wanesbbOpenCV-fayzvmciykwswxbvwtyujutmkjgz/Build/Products/Debug -filelist /Users/AOA/Library/Developer/Xcode/DerivedData/wanesbbOpenCV-fayzvmciykwswxbvwtyujutmkjgz/Build/Intermediates/wanesbbOpenCV.build/Debug/wanesbbOpenCV.build/Objects-normal/x86_64/wanesbbOpenCV.LinkFileList -mmacosx-version-min=10.7 -L/usr/local/Cellar/opencv/2.3.1a/lib -libopencv_core -libopencv_imgproc -libopencv_highgui -libopencv_ml -libopencv_video -libopencv_features2d -libopencv_calib3d -libopencv_objdetect -libopencv_contrib -libopencv_legacy -libopencv_flann -lopencv_core -lopencv_highgui -o /Users/AOA/Library/Developer/Xcode/DerivedData/wanesbbOpenCV-fayzvmciykwswxbvwtyujutmkjgz/Build/Products/Debug/wanesbbOpenCV

    ld: library not found for -libopencv_core
    Command /Developer/usr/bin/llvm-g++-4.2 failed with exit code 1


    ------------------------------------------------------------------------------------
    The code I entered was:

    #include <stdlib.h>
    #include <stdio.h>
    #include <opencv/cv.h>
    #include <opencv/highgui.h>


    int main (int argx, const char * argv[]){

    IplImage *img = cvLoadImage("/Users/AOA/Pictures/dvfsuite.jpeg",1);
    if(!img){
    printf("no pic\n");
    return 0;
    }

    cvNamedWindow("show",1);
    cvShowImage("show",img);
    cvWaitKey(0);
    cvReleaseImage(&img);
    cvDestroyWindow("show");
    return 0;
    }

    ---------------------------------------------------------------------------------------


    I tried going into build phase and manually finding/adding the missing library but to no avail. Any suggestions? jiminaus? :)
     
  5. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #5
    (When posting code, please put the code between [CODE] ... [/CODE] tags.)

    These are the flags from the ld command you posted that specifies the libraries to link your program against. The ones in red are incorrect, the one in green are correct. You need to remove the ones in red.


    The -l (lower-case L) option to ld links a target against a library. If the option is -lopencv_core, then the linker will look for a file called libcorecv_core.dylib or libopencv_core.a. Notice that you don't put the lib prefix in the option. To put another way, if you want to link against libopencv_core.a or libopencv_core.dylib, you need to add the -lopencv_core option to ld.

    When you add a framework, dynamic library, or static library to the Link Binary With Libraries part of a target's build phase, XCode will arrange for the correct -l option to be added to the ld command. I theorise that you've added libopencv_core and libopencv_highgui to the build phase, and these are the correct -l options in green above.

    I further theorise that the incorrect -l options in red above are coming from the Other Link Flags setting under the Linking section of your target's Build Settings. Remove these.
     
  6. lou.salome macrumors newbie

    Joined:
    Jan 4, 2012
    Location:
    California & London UK
    #6
    Noted. I followed your advice and it compiled successfully. jiminaus... a god amongst men. :D

     

Share This Page