开发者

Symbols not found while building OpenCV's Hello World

开发者 https://www.devze.com 2023-04-12 06:36 出处:网络
I just installed openCV via MacPorts, I also added the library folder to the compiler\'s settings. But then when trying to build the following code,

I just installed openCV via MacPorts, I also added the library folder to the compiler's settings. But then when trying to build the following code,

#include <cv.h>
#include <highgui.h>

int main(int argc, char **argv) {

    cvNamedWindow("My Window", 1);
    IplImage *img = cvCreateImage(cvSize(640, 480), IPL_DEPTH_8U, 1);
    CvFont font;
    double hScale = 1.0;
    double vScale = 1.0;
    int lineWidth = 1;
    cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX | CV_FONT_ITALIC, hScale, vScale,
            0, lineWidth);
    cvPutText(img, "Hello World!", cvPoint(200, 400), &font,
            cvScalar(255, 255, 0));
    cvShowImage("My Window", img);
    cvWaitKey();

    return 0;
}

I am getting a message while 开发者_Go百科building that states that all the symbols are not found.

What am I doing wrong?

**** Build of configuration Release for project OpenCv ****

make all 
Building file: ../main.cpp
Invoking: GCC C++ Compiler
g++ -I/opt/local/include/opencv -O3 -Wall -c -fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.cpp"
Finished building: ../main.cpp

Building target: OpenCv
Invoking: MacOS X C++ Linker
g++  -o "OpenCv"  ./main.o   
Undefined symbols:
  "_cvNamedWindow", referenced from:
      _main in main.o
  "_cvCreateImage", referenced from:
      _main in main.o
  "_cvShowImage", referenced from:
      _main in main.o
  "_cvPutText", referenced from:
      _main in main.o
  "_cvWaitKey", referenced from:
      _main in main.o
  "_cvInitFont", referenced from:
      _main in main.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [OpenCv] Error 1

**** Build Finished ****


There are two separate steps to getting an OpenCV project to compile and link. First is adding the header search path in order to compile, which you've already done.

You also have to add the libraries to the project in order to link. That's this part:

  • Select Project -> New Group and create a group called OpenCV frameworks
  • With the new group selected, select Project -> Add to Project…
  • Press the "/" key to get the Go to the folder prompt
  • Enter /usr/local/lib (/opt/local/lib if you used MacPorts)
  • Select libopencv_core.dylib, libopencv_highgui.dylib, and any other libraries required by your project.
  • Click Add
  • Uncheck Copy Items… and click Add

This came from the Mac OS X OpenCV Port section of the OpenCV wiki.

0

精彩评论

暂无评论...
验证码 换一张
取 消