OpenCV 2.0 Xcode 4

Discussion in 'Mac Programming' started by camilo.leon, May 1, 2011.

  1. macrumors newbie

    Joined:
    May 1, 2011
    Location:
    Berlin
    #1
    Hello guys

    I'm new on programming on macOSX, I have to write a code using openCV and c++, I explore the Mac OS X OpenCV Port and followed the instructions to install mac ports and I installed it and seems to be that I could build OpenCV 2.1.0 using that. The thing is that I have installed Xcode 4 but I can't find make it work. I have no idea what to do and I have tried looking on several web sites but none of them could help me.

    Any suggestion will be much appreciated. Thanks :)
     
  2. macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #2
    1. File | New | New Project ... (Shift+Cmd+N)
    2. Mac OS X, Application, Command Line Tool.
    3. Enter a project name. Change Type to C++.
    4. Choose place to store project.
    5. Click the target at the top of the tree on the left. Click your target (not project), then click Build Settings.
    6. Change Architectures to 64-bit Intel if you're using Mac OS X 10.6, to 32-bit Intel if you're using 10.5.
    7. Change Build Active Architecture Only, Debug to No.
    8. Change Header Search Paths to /opt/local/include /opt/local/include/opencv.
    9. Click Build Phases
    10. Expand Link Binary With Libraries
    11. Click +
    12. Click Add Other
    13. Navigate to /opt/local/lib
    14. Cmd+click the libopencv_*.dylib files your project needs (at a minimum you'll need core, highgui and imgproc).
    15. Click OK
     
  3. camilo.leon, May 7, 2011
    Last edited: May 7, 2011

    thread starter macrumors newbie

    Joined:
    May 1, 2011
    Location:
    Berlin
    #3
    Hey mate

    I did what you told me to do and I tried to build an example code that I have, I know that is not working because I haven't finished yet but I got this error.

    Ld /Users/camiloleon/Library/Developer/Xcode/DerivedData/OpenCVTest-dvxmawxdmlnefdboqlievdgeaxfg/Build/Products/Debug/OpenCVTest normal x86_64
    cd /Users/camiloleon/Desktop/OpenCVTest
    setenv MACOSX_DEPLOYMENT_TARGET 10.6
    /Developer/usr/bin/clang++ -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -L/Users/camiloleon/Library/Developer/Xcode/DerivedData/OpenCVTest-dvxmawxdmlnefdboqlievdgeaxfg/Build/Products/Debug -L/opt/local/lib -F/Users/camiloleon/Library/Developer/Xcode/DerivedData/OpenCVTest-dvxmawxdmlnefdboqlievdgeaxfg/Build/Products/Debug -filelist /Users/camiloleon/Library/Developer/Xcode/DerivedData/OpenCVTest-dvxmawxdmlnefdboqlievdgeaxfg/Build/Intermediates/OpenCVTest.build/Debug/OpenCVTest.build/Objects-normal/x86_64/OpenCVTest.LinkFileList -mmacosx-version-min=10.6 -lopencv_calib3d.2.2.0 -lopencv_contrib.2.2.0 -lopencv_core.2.2.0 -lopencv_features2d.2.2.0 -lopencv_flann.2.2.0 -lopencv_gpu.2.2.0 -lopencv_highgui.2.2.0 -lopencv_imgproc.2.2.0 -lopencv_legacy.2.2.0 -lopencv_ml.2.2.0 -lopencv_objdetect.2.2.0 -lopencv_video.2.2.0 -o /Users/camiloleon/Library/Developer/Xcode/DerivedData/OpenCVTest-dvxmawxdmlnefdboqlievdgeaxfg/Build/Products/Debug/OpenCVTest

    ld: duplicate symbol _main in /Users/camiloleon/Library/Developer/Xcode/DerivedData/OpenCVTest-dvxmawxdmlnefdboqlievdgeaxfg/Build/Intermediates/OpenCVTest.build/Debug/OpenCVTest.build/Objects-normal/x86_64/dip1.o and /Users/camiloleon/Library/Developer/Xcode/DerivedData/OpenCVTest-dvxmawxdmlnefdboqlievdgeaxfg/Build/Intermediates/OpenCVTest.build/Debug/OpenCVTest.build/Objects-normal/x86_64/main.o for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    Command /Developer/usr/bin/clang++ failed with exit code 1


    Command /Developer/usr/bin/clang++ failed with exit code 1

    sorry but I don't know if that is a code error or a build settings error. If would be great if you could help me.

    Thanks, what you told me really helps me.
     
  4. macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #4
    (Replacing long post with short one now that you gave the complete output.)

    There are two mains. Both the object file dip1.o (presumably compiled from dip1.cpp) and main.o (presumably compiled from main.cpp) both contain main. You need to get right of one of them.
     
  5. thread starter macrumors newbie

    Joined:
    May 1, 2011
    Location:
    Berlin
    #5
    I am using macOSX 10.6.7, Xcode Version 4.0.1 Build 4A1006 to install opencv I just typed sudo port install opencv. After that I installed several versions of python and another components because I need them for another project. I don't know if that could affect the opencv installation.

    What I'm going to do is to compile a simple code, a tutorial one like "hello world" only to see if everything is working. I'll let you know how is it going.

    thanks mate for your help.
     
  6. jiminaus, May 7, 2011
    Last edited: May 7, 2011

    macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #6
    Don't worry about it. None of my initial exploratory questions apply, now I've seen the actual error from ld. It's an issue with the project you're actually using.

    EDIT: Have you added anything to main.cpp, which XCode automatically created in your project? If not, clean your project, delete it, then re-build.
     
  7. thread starter macrumors newbie

    Joined:
    May 1, 2011
    Location:
    Berlin
    #7
    Hi mate,

    I just check and the installation is ok, I could compile the program and run it from the terminal.

    now I'm checking again set up for Xcode and I wanted to check if what I did is ok.
    On the Build Settings I put:
    Architectures: 64-bit Intel
    Build Active Architecture Only: No
    Header Search Paths: /opt/local/include/opencv
    /opt/local/lib : /opt/local/lib -> I didn't add that but I appears like that now.

    On the Build Phases Tab
    Link Binary With libraries: I add all the libopencv_XXXX.dylib -> the route of this files is opt/local/lib.

    once I run the program that works, what I get is /opt/local/include/opencv/highgui.h:45:10: fatal error: 'opencv2/core/core_c.h' file not found [1]
     
  8. macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #8
    Header Search Paths: /opt/local/include /opt/local/include/opencv

    You need both of these include paths. Separate them by a space.
     
  9. thread starter macrumors newbie

    Joined:
    May 1, 2011
    Location:
    Berlin
    #9
    Hey mate

    I works, there is no compilation errors, but now I can't see the image, I could see on the dock the application running and it opens a window that only shows the icons on closing and minimize but I can't see the image.

    My code is:

    #include "highgui.h"
    int main( int argc, char** argv )
    { IplImage* img = cvLoadImage("VRColombians.JPG");
    cvNamedWindow("Example1", CV_WINDOW_AUTOSIZE);
    cvShowImage("Example1", img);
    cvWaitKey(0);
    cvReleaseImage(&img);
    cvDestroyWindow("Example1");
    }

    I could see it if I write on Terminal ./project
     
  10. jiminaus, May 7, 2011
    Last edited: May 7, 2011

    macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #10
    You're using relative paths without setting the working directory to where you expect it to be. The default working directory is not the project directory, but the directory where the executable was built.

    Either:
    • Copy your resources into the build directory by adding them to the Copy File build phase of your target.
    • Call chdir at the start of program with the absolute path of the directory holding your resource
    • Set the working directory via XCode in the run command of the current scheme (Product | Edit Scheme...)

    BTW: To save the mods grief, please put your code between [code] ... [/code] tags.
     
  11. thread starter macrumors newbie

    Joined:
    May 1, 2011
    Location:
    Berlin
    #11
    My personal Jesus, I didn't say thank you.

    Thanks mate this was really helpful!!!!
     

Share This Page