简体   繁体   中英

OpenCV “referenced from: _main in main.o” build error

I am trying to run the following program in Xcode;

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

int TrackbarInitValue = 0;
int TrackbarStopValue;

CvCapture *capture = NULL;
IplImage *frame;

void onTrackbarSlide(int position)
{
    cvSetCaptureProperty(capture, CV_CAP_PROP_POS_FRAMES, position);
        // cvShowImage("Trackbar", frame);
}

int main(int argc, char **argv)
{
    cvNamedWindow("Trackbar", CV_WINDOW_AUTOSIZE);

    if(argc < 2)
    {
        printf("Please specify the video name n");
        exit(0);
    }

    capture = cvCreateFileCapture(argv[1]);
    TrackbarStopValue = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_COUNT);
    if(TrackbarStopValue != 0)
    {
        cvCreateTrackbar("Position", "Trackbar", &TrackbarInitValue, TrackbarStopValue, onTrackbarSlide);
    }

    while(1)
    {
        frame = cvQueryFrame(capture);
        if(!frame) break;
        int pos = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_POS_FRAMES);
        cvSetTrackbarPos("Position", "Trackbar", pos);
        cvShowImage("Trackbar", frame);
        char c = cvWaitKey(33);
        if( c == 27) break;
    }

    cvReleaseCapture(&capture);
    cvDestroyWindow("Trackbar");

    return 0;
}

And when I try to build, I get the following errors;

Ld build/Debug/TrackBarPlayer normal x86_64
cd "/Users/facebooth/C++ practice/OpenCV Practice/TrackBarPlayer"
setenv MACOSX_DEPLOYMENT_TARGET 10.6
/Developer/usr/bin/g++-4.2 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk "-L/Users/facebooth/C++ practice/OpenCV Practice/TrackBarPlayer/build/Debug" -L/opt/local/lib "-F/Users/facebooth/C++ practice/OpenCV Practice/TrackBarPlayer/build/Debug" -filelist "/Users/facebooth/C++ practice/OpenCV Practice/TrackBarPlayer/build/TrackBarPlayer.build/Debug/TrackBarPlayer.build/Objects-normal/x86_64/TrackBarPlayer.LinkFileList" -mmacosx-version-min=10.6 -o "/Users/facebooth/C++ practice/OpenCV Practice/TrackBarPlayer/build/Debug/TrackBarPlayer"

Undefined symbols:
  "_cvCreateFileCapture", referenced from:
      _main in main.o
  "_cvSetCaptureProperty", referenced from:
      onTrackbarSlide(int)  in main.o
  "_cvNamedWindow", referenced from:
      _main in main.o
  "_cvSetTrackbarPos", referenced from:
      _main in main.o
  "_cvCreateTrackbar", referenced from:
      _main in main.o
  "_cvShowImage", referenced from:
      _main in main.o
  "_cvQueryFrame", referenced from:
      _main in main.o
  "_cvDestroyWindow", referenced from:
      _main in main.o
  "_cvReleaseCapture", referenced from:
      _main in main.o
  "_cvWaitKey", referenced from:
      _main in main.o
  "_cvGetCaptureProperty", referenced from:
      _main in main.o
      _main in main.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

I'm a complete newbie to programming, and after literally hours of Googling, all I have discovered is that it's a linking problem. If anyone could give me some guidance on how to fix it, or what these errors are even actually saying, it would be very much appreciated.

链接libopencv_videoio.3.2.6.dylib

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM