OpenCV error using g++ to compile (Mountain Lion 10.8)

so I recently got OpenCV built on my mac using homebrew and I attempted to run the following hello,world ish program that I got from a stackoverflow user when I got an error.

Here is the program:

#include "/usr/local/include/opencv/cv.h"
#include "/usr/local/include/opencv/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;
}

Here is the subsequent error: (command to compile was g++ lol.cpp)

Undefined symbols for architecture x86_64:
  "_cvCreateImage", referenced from:
      _main in ccxOWdix.o
  "_cvInitFont", referenced from:
      _main in ccxOWdix.o
  "_cvNamedWindow", referenced from:
      _main in ccxOWdix.o
  "_cvPutText", referenced from:
      _main in ccxOWdix.o
  "_cvShowImage", referenced from:
      _main in ccxOWdix.o
  "_cvWaitKey", referenced from:
      _main in ccxOWdix.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

What am I doing wrong?

Answers


You need to link the libraries. Have a look at "4) Configure your own projects to use OpenCV" here: http://opencv.willowgarage.com/wiki/InstallGuide


Need Your Help

Check if previous clicked value is inside an array

jquery

I have a list with different categories. All the list item are clickable. I want the user to pick between 1 and 3 items. They can toggle their choice, but maximum is alway 3. So far, so good.

IPhone YUV channel orientation

iphone objective-c camera avfoundation

I am grabbing the YUV channel from the IPhone in the kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange format (YUV, bi-planar).

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.