foresea
foresea

Reputation: 73

Undefined symbols for architecture x86_64 Using QT with Opencv

I am using QT's IDE with OpenCV. The code works fine in Xcode but when I copy them to QT for GUI design, it doesn't work at all. I searched like crazy...

Here is the error message:

    /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:

So it should be the link error with opencv I think.

#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 file:


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

I have tried this answer but it doesn't work for me: QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.6 to 10.9

Could anyone help me? Thanks.

Upvotes: 3

Views: 1969

Answers (1)

L&#225;szl&#243; Papp
L&#225;szl&#243; Papp

Reputation: 53173

I think you will need to change from the default gnu C++ std implementation to the following by passing it to your compiler, which is presumably clang:

-stdlib=libc++

In short, do not mix gcc and clang if you do that because unfortunately they are not 100% abi compatible, sadly. You could check which one the libopencv was built with:

otool -L libopencv-version.dylib

Upvotes: 2

Related Questions