opencv用clang ok编译,用gcc不好os x 10.9 [英] opencv compile with clang ok, with gcc not ok os x 10.9

查看:132
本文介绍了opencv用clang ok编译,用gcc不好os x 10.9的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在OS X 10.9上,安装了opencv-2.4.8.2.我正在尝试编译一个简单的代码:

I am on OS X 10.9, with opencv-2.4.8.2 installed. I am trying to compile a simple code:

#include <stdio.h>
#include <opencv2/opencv.hpp>

using namespace cv;

int main(int argc, char** argv )
{
    if ( argc != 2 )
    {
        printf("usage: DisplayImage.out <Image_Path>\n");
        return -1;
    }

    Mat image;
    image = imread( argv[1], 1 );

    if ( !image.data )
    {
        printf("No image data \n");
        return -1;
    }
    namedWindow("Display Image", WINDOW_AUTOSIZE );
    imshow("Display Image", image);

    waitKey(0);

    return 0;
}

并可以使用clang(/usr/bin/g ++ -arch x86_64 pkg-config opencv --libs test.cpp)做到这一点,但不能使用gcc 4.9(/usr/local/bin/g ++ -arch x86_64 pkg-config opencv --libs test.cpp).

and can do that with clang (/usr/bin/g++ -arch x86_64 pkg-config opencv --libs test.cpp), but not with gcc 4.9 (/usr/local/bin/g++ -arch x86_64 pkg-config opencv --libs test.cpp).

这是我在gcc 4.9中得到的:

This is what I get with gcc 4.9:

$ /usr/local/bin/g++ `pkg-config opencv --libs` test.cpp
Undefined symbols for architecture x86_64:
  "cv::namedWindow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)", referenced from:
      _main in cc52UZjK.o
  "cv::imread(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)", referenced from:
      _main in cc52UZjK.o
  "cv::imshow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)", referenced from:
      _main in cc52UZjK.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status

有人可以帮我找出原因吗?

Can anyone help me figure out why?

有关我的编译器的信息:

info about my compilers:

$/usr/bin/gcc -v配置为:--prefix =/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir =/usr/include/c ++/4.2.1Apple LLVM版本5.1(clang-503.0.40)(基于LLVM 3.4svn)目标:x86_64-apple-darwin13.1.0线程模型:posix

$ /usr/bin/gcc -v Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn) Target: x86_64-apple-darwin13.1.0 Thread model: posix

$/usr/local/bin/gcc -v使用内置规格.COLLECT_GCC =/usr/local/bin/gccCOLLECT_LTO_WRAPPER =/usr/local/libexec/gcc/x86_64-apple-darwin13.0.0/4.9.0/lto-wrapper目标:x86_64-apple-darwin13.0.0配置为:../gcc-4.9-20131215/configure --enable-languages = c ++,fortran螺纹型号:posixgcc版本4.9.0 20131215(实验性)(GCC)

$ /usr/local/bin/gcc -v Using built-in specs. COLLECT_GCC=/usr/local/bin/gcc COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-apple-darwin13.0.0/4.9.0/lto-wrapper Target: x86_64-apple-darwin13.0.0 Configured with: ../gcc-4.9-20131215/configure --enable-languages=c++,fortran Thread model: posix gcc version 4.9.0 20131215 (experimental) (GCC)

推荐答案

简短的答案是:您不能使用GCC在OS X 10.9和更高版本上构建C ++代码,因为Apple切换为使用libc ++而不是libstdc ++,并且GCC不兼容与该运行时.已经进行了很多尝试来找到一种解决方法,但最终结果却是不可行的.

The short answer is: you cannot use GCC to build C++ code on OS X 10.9 and newer, because Apple switched to using libc++ instead of libstdc++ and GCC is incompatible with that runtime. Many attempts have been made to find a workaround, but in the end it turned out to be infeasible.

这篇关于opencv用clang ok编译,用gcc不好os x 10.9的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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