体系结构的未定义符号x86_64将QT与Opencv一起使用

时间:2014-05-17 02:55:14

标签: qt opencv

我正在使用QT的IDE和OpenCV。代码在Xcode中运行良好,但是当我将它们复制到QT进行GUI设计时,它根本不起作用。我疯狂地搜索......

以下是错误消息:

    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -c -pipe -g -gdwarf-2 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -mmacosx-version-min=10.9 -Wall -W -fPIE -DQT_CORE_LIB -I../../../../Qt/5.2.1/clang_64/mkspecs/macx-clang -I../Hello -I/usr/local/include -I../../../../Qt/5.2.1/clang_64/lib/QtCore.framework/Versions/5/Headers -I. -I. -F/Users/Chenxi/Qt/5.2.1/clang_64/lib -o main.o ../Hello/main.cpp
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -headerpad_max_install_names -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -mmacosx-version-min=10.9 -o Hello main.o   -F/Users/Chenxi/Qt/5.2.1/clang_64/lib -L/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_objdetect -lopencv_calib3d -framework QtCore 
Undefined symbols for architecture x86_64:
  "cv::imread(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int)", 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)
make: *** [Hello] Error 1

main.cpp中:

所以我认为应该是与opencv的链接错误。

#include <QCoreApplication>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv/cv.h>
#include <iostream>


using namespace std;
using namespace cv;

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    cout<<"hello world"<<endl;
    Mat test(10,10,CV_8UC1);
    cout<<test.cols<<endl;

    Mat test1 = imread("/Users/master/desktop/FYP/GUI/Demo_db/neg_1.png");

    return a.exec();
}

.pro文件:


QT       += core

QT       -= gui

TARGET = Hello
CONFIG   += console
CONFIG   -= app_bundle

TEMPLATE = app

INCLUDEPATH += /usr/local/include

LIBS += -L/usr/local/lib \
    -lopencv_core \
    -lopencv_imgproc \
    -lopencv_highgui \
    -lopencv_objdetect \
    -lopencv_calib3d


SOURCES += main.cpp

我已经尝试过这个答案,但它对我不起作用: QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.6 to 10.9

有人能帮帮我吗?感谢。

1 个答案:

答案 0 :(得分:2)

我认为您需要将默认的gnu C ++ std实现更改为以下内容,方法是将其传递给编译器,这可能是clang:

-stdlib=libc++

简而言之,如果你这样做,不要混用gcc和clang因为遗憾的是它们不是100%abi兼容的。你可以检查libopencv是用哪一个构建的:

otool -L libopencv-version.dylib