Reputation: 93
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 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 ****
Upvotes: 2
Views: 2118
Reputation: 10738
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:
This came from the Mac OS X OpenCV Port section of the OpenCV wiki.
Upvotes: 2