c++opencvlinkerxcode4

OpenCV cvSmooth linker error


I'm developing with XCode 4 and I linked the OpenCV libraries to create some experimental projects.

If have found problems trying to compile this lines:

int main (int argc, const char * argv[])
{
    IplImage* img = cvLoadImage( argv[1]);
    cvNamedWindow( "Example3-in" );
    cvNamedWindow( "Example3-out" );

    // Show the original image
    cvShowImage("Example3-in", img);

    // Create an image for the output
    IplImage* out = cvCreateImage( cvGetSize(img), IPL_DEPTH_8U, 3 );

    // Perform a Gaussian blur
    cvSmooth( img, out, CV_GAUSSIAN, 11, 11 );

    // Show the processed image
    cvShowImage("Example3-out", out);

    cvWaitKey(0);
    cvReleaseImage( &img );
    cvReleaseImage( &out );
    cvDestroyWindow( "Example3-in" );
    cvDestroyWindow( "Example3-out" );
    return 0;
}

Problems:

Undefined symbols for architecture x86_64:
  "_cvSmooth", referenced from:
      _main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

In my opinion is like the libraries are not compiled for a 64bit architecture...

Note:

The libraries where installed via MacPorts


Solution

  • The ones installed on my system are x86_64. I downloaded the sources and compiled them myself.

    I was going to suggest another alternative: force XCode to build i386 but it seems it's not possible.

    You can, however, force the compilation to be i386 through the cmd-line:

    g++ main.cpp -o app `pkg-config --cflags --libs opencv` -m32 -arch i386
    

    Keep in mind that all the libraries your application links to needs to have the same architecture.