我刚刚通过MacPorts安装了openCV, 我还将库文件夹添加到编译器的设置中。 但是在尝试构建以下代码时,
#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 ****
答案 0 :(得分:2)
要使OpenCV项目进行编译和链接,有两个单独的步骤。首先是添加标题搜索路径以便编译,您已经完成了。
您还必须将库添加到项目中才能进行链接。这就是这个部分:
这来自OpenCV维基的Mac OS X OpenCV Port部分。