2011-10-09 2 views
2

방금 ​​MacPorts를 통해 openCV를 설치했습니다. 또한 라이브러리 폴더를 컴파일러 설정에 추가했습니다. 그러나 다음 코드를 구축을 위해 노력하고,OpenCV의 Hello World를 빌드하는 동안 기호를 찾을 수 없습니다.

#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; 
} 

나는 모든 기호가 발견되지 없다는 메시지 동안 건물을 얻고있다.

내가 뭘 잘못하고 있니?

**** 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 **** 

답변

2

OpenCV 프로젝트를 컴파일하고 링크하는 데는 두 가지 단계가 있습니다. 첫 번째는 이미 수행 한 컴파일을 위해 헤더 검색 경로를 추가하는 것입니다.

링크하려면 프로젝트에 라이브러리를 추가해야합니다. 즉,이 부분 :

  • 선택 프로젝트 -> 새 그룹과 OpenCV의라는 그룹이 선택한 새 그룹을 선택 프로젝트와
  • 을 프레임 워크 생성 - ...
  • 눌러 "/"키> 프로젝트에 추가
  • 는/usr/지방/lib 디렉토리 (/ 옵션/지역/lib에 당신이 MacPorts를 사용하는 경우)
  • 선택 libopencv_core.dylib, libopencv_highgui.dylib 및 프로젝트에 필요한 다른 라이브러리 입력 폴더 프롬프트로 이동을 얻을.
  • 클릭 ...
  • 의 선택을 취소 복사 항목을 추가하고 이것은 OpenCV의 위키의 Mac OS X OpenCV Port 섹션에서 온

추가를 클릭합니다.

관련 문제