OpenCv + mac os x + qt creator =奇怪的链接bug? [英] OpenCv + mac os x + qt creator = strange linking bug?

查看:599
本文介绍了OpenCv + mac os x + qt creator =奇怪的链接bug?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Mac Os X 10.9上使用qt creator构建简单的OpenCV应用程序。所以我使用brew安装了OpenCv和Qt4:

I'm trying to build simple OpenCV app using qt creator on Mac Os X 10.9. So i've installed OpenCv and Qt4 using brew:

brew install opencv
brew install qt4

,然后下载qt creator。比我做的简单的项目 - main.cpp:

and then downloaded qt creator. Than i've made simple project - main.cpp:

#include <QCoreApplication>
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    Mat m;
    m = Mat(2, 3, 4);
    cv::threshold(m, m, 123, 200, 1);
    m = cv::imread("asdasd", 1); //problem is here!
    return a.exec();
}

和.pro档案:

QT       += core
QT       -= gui
TARGET = opencv_test
CONFIG   += console
CONFIG   -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
LIBS += -L/usr/local/lib \
    -lopencv_core \
    -lopencv_imgproc \
    -lopencv_highgui \
    -lopencv_objdetect \
    -lopencv_calib3d

INCLUDEPATH += /usr/local/include/opencv
DEPENDPATH += /usr/local/include/opencv/include

INCLUDEPATH += $$PWD/../../../usr/local/include
DEPENDPATH += $$PWD/../../../usr/local/include
DEPENDPATH += $$PWD/../../../usr/local/lib

现在奇怪的部分 - 如果我注释这行: m = cv :: imread(asdasd,1); //问题就在这里!和构建项目,一切都很好 - 它会编译和链接没有任何问题。所以看起来 .dylib 文件是确定的,因为我可以使用OpenCV函数 - Mat 对象构造函数和 threshold 函数。但!如果我没有评论行与imread我得到这个错误:: - 1:błąd:symbol(s)没有找到架构x86_64 或更精确: p>

Now the weird part - if i comment this line: m = cv::imread("asdasd", 1); //problem is here! and build project, everything is fine - it will compile and link without any problem. So it seems that .dylib files are ok, because i can use OpenCV functions - Mat object constructor and threshold function. But! If i don't comment line with imread i get this error: :-1: błąd:symbol(s) not found for architecture x86_64 or to be more precise:


架构x86_64的未定义符号:cv :: imread(std :: string
const& int),引用自:
_main in main.o ld:没有为架构找到符号x86_64 clang:error:linker命令失败,退出代码1(使用-v查看
调用)

Undefined symbols for architecture x86_64: "cv::imread(std::string 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)

通常问题只是较大问题的一部分 - 我试图使用qt creator构建更大的项目,但链接器找不到一些所有!)函数。在使用很多OpenCV函数的项目中,链接器只有以下问题:

Generally the problem is just a part of bigger problem - i'm trying to build much bigger project using qt creator, but linker can't find some(but not all!) functions. In project which uses lot of OpenCV functions linker has got problems only with:

cv::VideoCapture::VideoCapture(std::string const&)
cv::destroyWindow(std::string const&)
cv::CascadeClassifier::detectMultiScale(cv::Mat const&, std::vector<cv::Rect_<int>, std::allocator<cv::Rect_<int> > >&, double, int, int, cv::Size_<int>, cv::Size_<int>)
cv::CascadeClassifier::CascadeClassifier(std::string const&)
cv::imshow(std::string const&, cv::_InputArray const&)

在这个项目中,我使用了更多的函数(主要是基本的图像处理 - 阈值,图像复制,绘制基本图元,查找轮廓),链接器可以处理它们没有任何问题。

In this project i'm using much more functions (mostly basic image processing - threshold, image copying, drawing basic primitives, finding contours) and linker can handle them without any problem.

我已经尝试过 - 构建OpenCv和Qt4(只使用构建 brew install qt4 --from-source )。我已经使用这个教程建造的OpenCV - 的http:// sadeepj.blogspot.com/2012/03/installing-and-configuring-opencv-to.html 我也尝试了很多CMake的选择 - -DCMAKE_OSX_ARCHITECTURES = x86_64或i386和 -DCMAKE_CXX_FLAGS = - stdlib = libc ++。我也试图使用gcc(defautt编译器是clang)版本4.2构建它,但它失败(构建失败)。
我试过使用OpenCV 2.4.8和2.4.2。
我也尝试设置:

What i've already tried - building OpenCv and Qt4(only using build brew install qt4 --from-source) from sources. I've builded OpenCv using this tutorial - http://sadeepj.blogspot.com/2012/03/installing-and-configuring-opencv-to.html I've also tried a lot of CMAKE options - -DCMAKE_OSX_ARCHITECTURES=x86_64 or i386 and -DCMAKE_CXX_FLAGS="-stdlib=libc++". I've also tried to build it using gcc(defautt compiler is clang) version 4.2, but it failed(building failed). i've tried with OpenCV 2.4.8 and 2.4.2. Also i've tried to set:

CMAKE_CXX_FLAGS += -std=c++11
CMAKE_CXX_FLAGS += -stdlib=stdlibc++

仍然没有运气。

我检查了构建的.dylib文件是否为x86_64:

I've checked whether builded .dylib files are x86_64:


/ usr / local / -info libopencv_core.dylib非FAT文件:
libopencv_core.dylib是架构:x86_64的

/usr/local/lib[master]$ lipo -info libopencv_core.dylib Non-fat file: libopencv_core.dylib is architecture: x86_64

和highgui文件是否包含任何关于 imread 功能的信息(我知道这是不是它导出此函数的证明):

and whether highgui file contains any information about imread function(i know that it is not a proof that it export this function):

/usr/local/lib[master]$ nm libopencv_highgui.dylib | grep imread
00000000000069b0 T __ZN2cv6imreadERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEEi
0000000000006ac0 t __ZN2cvL7imread_ERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEEiiPNS_3MatE



信息,这可能是重要的:Mac OS X 10.9,64位。

Information which might be important: Mac OS X 10.9, 64 bit.

/usr/local/lib[master]$ clang --version
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix
/usr/local/lib[master]$ gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix

Btw - 运行 gcc --version 事实运行clang?

Btw - isn't it strange that running gcc --version in fact runs clang ?

所以问题是 - 我可以做什么来编译和构建?我应该尝试使用gcc或者其他的东西会解决这个问题?此外 - 如果有人可以上传他的图书馆和共享一个链接,所以我可以尝试与他们,这将是巨大的。任何解决方案,将解决这个问题将对我很好 - 我可以建立一切从源,使用任何编译器,链接器等..只是帮助我使它工作,我会很高兴:)

So the question is - what can i do to compile and build it? Should i try using gcc or maybe something else will solve this problem? Also - if someone could upload his libraries and share a link it, so i could try with them it would be great. Any solution that will solve this problem will be fine for me - i can build everything from source, use any compiler, linker, etc.. - just help me make it working and i will be happy :)

推荐答案

确定 - 最后经过4天的搜索我已经解决了这个问题。一般来说解决方案很简单 - 只需添加:

Ok - finally after 4 days of searching i've solved this problem. Generally solution is simple - just add:

QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.9

到您的.pro文件。如果不想将其添加到每个.pro文件中,您可以将其设置为全局 - 只需将其设置在此文件中:

to you .pro file. If don't want to add it to every .pro file you can set it "globally" - just set it in this file:

Qt5.2.0/5.2.0-rc1/clang_64/mkspecs/macx-clang/qmake.conf 

有关此错误/问题的更多信息:

- SOLVED- Qt5.1 / Qt5.2 + Mac OS 10.9(Mavericks)+ XCode 5.0.2,架构x86_64的未定义符号 < br>
http://qt-project.org/forums/viewthread/35646/ < ; - 大多在这里

More information about this bug/problem:
-SOLVED- Qt5.1/Qt5.2 + Mac OS 10.9 (Mavericks) + XCode 5.0.2 , Undefined symbols for architecture x86_64
http://qt-project.org/forums/viewthread/35646/ <-- mostly here

//编辑:

这个解决方案只适用于CLANG,没有gcc的运气。

//edit:
This solution only works with CLang, no luck with gcc.

这篇关于OpenCv + mac os x + qt creator =奇怪的链接bug?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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