在Qt Android项目中使用OpenCV时的链接顺序

时间:2014-12-17 14:49:50

标签: android c++ windows qt opencv

我正在尝试在我使用Qt Creator构建的Qt Android项目中使用OpenCV。

我使用预先构建的OpenCV-2.4.10-android-sdk,并根据它们的大小来判断,我正在链接到静态库。现在我收到链接器错误,并且由于链接顺序在GCC中很重要,我怀疑它们是因为我的链接顺序不正确(libs按字母顺序排列)。

那么正确的链接顺序是什么,我如何找到它,考虑到我在Windows上进行交叉编译?

这是来自我的.pro文件:

LIBS += -L"c:/Workspace/OpenCV-2.4.10-android-sdk/sdk/native/libs/armeabi-v7a"\
        -L"c:/Workspace/OpenCV-2.4.10-android-sdk/sdk/native/3rdparty/libs/armeabi-v7a"
LIBS += \
    -lopencv_core\
    -lopencv_features2d\
    -lopencv_flann\
    -lopencv_highgui\
    -lopencv_imgproc\
    -lopencv_legacy\
    -lopencv_ml\
    -lopencv_objdetect\
    -lopencv_ocl\
    -lopencv_photo\
    -lopencv_stitching\
    -lopencv_superres\
    -lopencv_ts\
    -lopencv_video\
    -lopencv_videostab\
    -lIlmImf\
    -llibjasper\
    -llibjpeg\
    -llibpng\
    -llibtiff\
    -ltbb

这就是我现在收到的错误:

c:/Workspace/OpenCV-2.4.10-android-sdk/sdk/native/libs/armeabi-v7a/libopencv_core.a(parallel.cpp.o):parallel.cpp:function tbb::interface6::internal::start_for<tbb::blocked_range<int>, (anonymous namespace)::ProxyLoopBody, tbb::auto_partitioner const>::~start_for(): error: undefined reference to 'vtable for tbb::task'

1 个答案:

答案 0 :(得分:4)

对于可能遇到同样问题的任何人,这是OpenCV的正确顺序。我在c:\Workspace\OpenCV-2.4.10-android-sdk\sdk\native\jni\OpenCVModules_armeabi_v7a.cmake

中找到了它
foreach(_expectedTarget libtiff libjpeg libjasper libpng IlmImf tbb opencv_core opencv_androidcamera opencv_flann opencv_imgproc opencv_highgui opencv_features2d opencv_calib3d opencv_ml opencv_objdetect opencv_video opencv_contrib opencv_photo opencv_java opencv_legacy opencv_ocl opencv_stitching opencv_superres opencv_ts opencv_videostab)

按照foreach中给出的顺序编译时,它们起作用了。我找不到任何可以给我正确订单的工具,至少不适用于Windows上的Android NDK。

这就是LIBS条目的外观:

LIBS += -L"c:/Workspace/OpenCV-2.4.10-android-sdk/sdk/native/libs/armeabi-v7a"\
        -L"c:/Workspace/OpenCV-2.4.10-android-sdk/sdk/native/3rdparty/libs/armeabi-v7a"
LIBS += \
    -llibtiff\
    -llibjpeg\
    -llibjasper\
    -llibpng\
    -lIlmImf\
    -ltbb\
    -lopencv_core\
    -lopencv_androidcamera\
    -lopencv_flann\
    -lopencv_imgproc\
    -lopencv_highgui\
    -lopencv_features2d\
    -lopencv_calib3d\
    -lopencv_ml\
    -lopencv_objdetect\
    -lopencv_video\
    -lopencv_contrib\
    -lopencv_photo\
    -lopencv_java\
    -lopencv_legacy\
    -lopencv_ocl\
    -lopencv_stitching\
    -lopencv_superres\
    -lopencv_ts\
    -lopencv_videostab