在xcode 4.5.1上链接库OpenCV 2.4.2 [英] Linking libraries OpenCV 2.4.2 on xcode 4.5.1

查看:130
本文介绍了在xcode 4.5.1上链接库OpenCV 2.4.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经按照以下说明在Macports上安装了opencv:

I have installed opencv with macports following the directions here: Compile OpenCV (2.3.1+) for OS X Lion / Mountain Lion with Xcode

我也已经在stackexchange和google上搜索并尝试了所有其他变体,但这似乎使我离得最近.

I have also search and tried every other variation of this on stackexchange and google, but this seems to get me closest.

它似乎可以用于某些方面,但不适用于2.4.2附带的示例代码.请注意,我已经添加了所有带有库的opencv 2.4.2 dylibs链接二进制文件.

It seems to work for some things, but not for sample code that ships with 2.4.2. Note that I have added ALL opencv 2.4.2 dylibs Link Binary with Libraries.

例如,以下将编译并运行:

For example, the following will compile and run:

#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>

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

但是,当我尝试构建如下所示的任何示例(例如display_image.cpp)时,出现链接错误.

However, when I try to build any of the samples, such as the display_image.cpp, example, as follows, I get link errors.

-不起作用-

 #include <stdio.h>
 #include <iostream>
 #include "opencv2/imgproc/imgproc.hpp"
 #include "opencv2/highgui/highgui.hpp"
 #include "opencv2/flann/miniflann.hpp"

 using namespace cv; // all the new API is put into "cv" namespace. Export its content
 using namespace std;
 using namespace cv::flann;

static void help()
{
    cout <<
    "\nThis program shows how to use cv::Mat and IplImages converting back and forth.\n"
    "It shows reading of images, converting to planes and merging back, color conversion\n"
    "and also iterating through pixels.\n"
    "Call:\n"
    "./image [image-name Default: lena.jpg]\n" << endl;
}

int main(int argc, char *argv[])
{
    help();
    const char* imagename = argc > 1 ? argv[1] : "lena.jpg";
    Mat img = imread(imagename); // the newer cvLoadImage alternative, MATLAB-style function
    if(img.empty())
    {
        fprintf(stderr, "Can not load image %s\n", imagename);
        return -1;
    }
    if( !img.data ) // check if the image has been loaded properly
        return -1;

    Mat img_yuv;
    cvtColor(img, img_yuv, CV_BGR2YCrCb); // convert image to YUV color space. The output image will be created automatically

    vector<Mat> planes; // Vector is template vector class, similar to STL's vector. It can store matrices too.
    split(img_yuv, planes); // split the image into separate color planes

    imshow("image with grain", img);

    waitKey();

    return 0;

}


我收到以下错误:


I get the following errors:

Undefined symbols for architecture x86_64:
 "cv::split(cv::Mat const&, std::__1::vector<cv::Mat, std::__1::allocator<cv::Mat> >&)", referenced from:
  _main in main1.o
 "cv::imread(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int)", referenced from:
  _main in main1.o
 "cv::imshow(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cv::_InputArray const&)", referenced from:
  _main in main1.o
 ld: symbol(s) not found for architecture x86_64
 clang: error: linker command failed with exit code 1 (use -v to see invocation)

有什么办法解决这个问题吗?

Any idea how to resolve this?

推荐答案

我遇到了同样的问题. Xcode 4.5中的构建设置默认设置似乎有所不同.

I had the same problem. A build setting default seems to be different in Xcode 4.5.

在内部设置"下-> Apple LLVM编译器4.1-语言>

Under "Build Settings"--> Apple LLVM compiler 4.1 - Language >

C ++标准库:= libc ++ (LLVM ...)更改为 libstdc ++ (GNU C ++ ...).

C++ Standard Library:= Change from libc++ (LLVM ...) to libstdc++ (GNU C++ ...).

这篇关于在xcode 4.5.1上链接库OpenCV 2.4.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆