【问题标题】:opencv compile with clang ok, with gcc not ok os x 10.9opencv 用 clang 编译 ok,用 gcc 不 ok os x 10.9
【发布时间】:2014-06-23 14:08:38
【问题描述】:

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

#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) )。

这就是我使用 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

谁能帮我找出原因?

关于我的编译器的信息:

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

$ /usr/local/bin/gcc -v 使用内置规范。 COLLECT_GCC=/usr/local/bin/gcc COLLECT_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 线程模型:posix gcc 版本 4.9.0 20131215(实验性)(GCC)

【问题讨论】:

  • 我相信您的问题与链接的问题相同。不过,我要为您发布一个包含足够信息以快速识别您的问题的问题表示赞赏。

标签: macos opencv gcc clang gcc4.9


【解决方案1】:

简短的回答是:您不能使用 GCC 在 OS X 10.9 和更高版本上构建 C++ 代码,因为 Apple 转而使用 libc++ 而不是 libstdc++ 并且 GCC 与该运行时不兼容。已经进行了许多尝试来寻找解决方法,但最终证明是不可行的。

【讨论】:

    猜你喜欢
    • 2013-11-01
    • 1970-01-01
    • 2018-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-06
    • 2013-11-10
    • 1970-01-01
    相关资源
    最近更新 更多