为arm64-v8a编译Qt和OpenCV

时间:2018-07-13 07:26:45

标签: android c++ qt opencv arm64

我正在尝试使用Qt和OpenCV编译用于arm64-v8a的程序 我创建了一个使用Qt的arm64-v8a版本的工具包,但遇到了大量未定义的参考错误

我使用以下参数编译了Qt:

./configure -xplatform android-clang \
 --disable-rpath -nomake tests -nomake examples \
 -android-ndk <ndk-r16b-root> -android-sdk <sdk-root> -android-ndk-host linux-x86_64 \
 -android-toolchain-version 4.9 -android-ndk-platform android-21 -android-arch arm64-v8a \
 -skip qttranslations -skip qtserialport -skip qtwebengine -no-warnings-are-errors \
 -prefix <install-dir> -opensource -confirm-license

然后我添加了2个编译器,第一个用于C,第二个用于C ++:

<ndk-r16b-root>/toolchains/llvm/prebuilt/linux-x86_64/bin/clang

with ABI: arm-linux-android-elf-64-bit

<ndk-r16b-root>/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++

with ABI: arm-linux-android-elf-64-bit

我为此版本的Qt克隆了自动检测到的工具包,并使用了以下设置:

Device type : Android Device
Device : Run on Android (default for Android)
Sysroot : <ndk-r16b-root>/platforms/android-21/arch-arm64
Compilers : the 2 above
Android GDB server : <ndk-r16b-root>/prebuilt/android-arm64/gdbserver/gdbserver
Qt version : the one I just compiled
Qt mkspec : android-clang

其他字段保留为空/默认情况下

我的.pro文件如下:

QT += quick multimedia multimediawidgets
CONFIG += c++11

# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

HEADERS += <my-headers>
SOURCES += <my-sources>

RESOURCES += qml/qml.qrc

INCLUDEPATH += OpenCV-android-sdk/sdk/native/jni/include

LIBS += -L"OpenCV-android-sdk/sdk/native/3rdparty/libs/arm64-v8a"\
        -L"OpenCV-android-sdk/sdk/native/libs/arm64-v8a"\
        -llibtiff\
        -llibjpeg\
        -llibjasper\
        -llibpng\
        -lIlmImf\
        -llibwebp\
        -lopencv_core\
        -ltbb\
        -lopencv_flann\
        -lopencv_imgproc\
        -lopencv_highgui\
        -lopencv_features2d\
        -lopencv_calib3d\
        -lopencv_ml\
        -lopencv_objdetect\
        -lopencv_video\
        -lopencv_photo\
        -lopencv_videostab\
        -ltegra_hal\
        -lopencv_imgcodecs\
        -lopencv_shape\
        -lopencv_stitching\
        -lopencv_superres\
        -lopencv_videoio

# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =

# Additional import path used to resolve QML modules just for Qt Quick Designer
QML_DESIGNER_IMPORT_PATH =

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

DISTFILES += \
    android/AndroidManifest.xml \
    android/gradle/wrapper/gradle-wrapper.jar \
    android/gradlew \
    android/res/values/libs.xml \
    android/build.gradle \
    android/gradle/wrapper/gradle-wrapper.properties \
    android/gradlew.bat

ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android

OpenCV-android-sdk文件夹来自here,使用3.2.0 Android Pack。

当我尝试编译时,会得到大量未定义的引用,如下所示:

OpenCV-android-sdk/sdk/native/libs/arm64-v8a/libopencv_core.a(matrix.cpp.o): In function `cv::SparseMat::newNode(int const*, unsigned long)':
matrix.cpp:(.text._ZN2cv9SparseMat7newNodeEPKim+0x4b8): undefined reference to `std::__throw_length_error(char const*)'
OpenCV-android-sdk/sdk/native/libs/arm64-v8a/libopencv_core.a(matrix.cpp.o): In function `std::vector<cv::Mat, std::allocator<cv::Mat> >::_M_fill_insert(__gnu_cxx::__normal_iterator<cv::Mat*, std::vector<cv::Mat, std::allocator<cv::Mat> > >, unsigned long, cv::Mat const&)':
matrix.cpp:(.text._ZNSt6vectorIN2cv3MatESaIS1_EE14_M_fill_insertEN9__gnu_cxx17__normal_iteratorIPS1_S3_EEmRKS1_[_ZNSt6vectorIN2cv3MatESaIS1_EE14_M_fill_insertEN9__gnu_cxx17__normal_iteratorIPS1_S3_EEmRKS1_]+0xcd4): undefined reference to `std::__throw_length_error(char const*)'
OpenCV-android-sdk/sdk/native/libs/arm64-v8a/libopencv_core.a(matrix.cpp.o): In function `std::vector<cv::UMat, std::allocator<cv::UMat> >::_M_fill_insert(__gnu_cxx::__normal_iterator<cv::UMat*, std::vector<cv::UMat, std::allocator<cv::UMat> > >, unsigned long, cv::UMat const&)':
matrix.cpp:(.text._ZNSt6vectorIN2cv4UMatESaIS1_EE14_M_fill_insertEN9__gnu_cxx17__normal_iteratorIPS1_S3_EEmRKS1_[_ZNSt6vectorIN2cv4UMatESaIS1_EE14_M_fill_insertEN9__gnu_cxx17__normal_iteratorIPS1_S3_EEmRKS1_]+0xbb0): undefined reference to `std::__throw_length_error(char const*)'

实际使用的链接器命令(发生错误的地方)是:

<ndk-r16b-root>/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ -D__ANDROID_API__=26 -target aarch64-none-linux-android -gcc-toolchain <ndk-r16b-root>/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64 -Wl,--exclude-libs,libgcc.a --sysroot=<ndk-r16b-root>/platforms/android-26/arch-arm64/ -Wl,-soname,libTest.so -Wl,-rpath-link=<newly-compiled-Qt-root>/lib -Wl,--no-undefined -Wl,-z,noexecstack -shared -o libTest.so myfilter.o qml_main_qml.o qmlcache_loader.o   -L<ndk-r16b-root>/sources/cxx-stl/llvm-libc++/libs/arm64-v8a -LOpenCV-android-sdk/sdk/native/3rdparty/libs/arm64-v8a -LOpenCV-android-sdk/sdk/native/libs/arm64-v8a -llibtiff -llibjpeg -llibjasper -llibpng -lIlmImf -llibwebp -lopencv_core -ltbb -lopencv_flann -lopencv_imgproc -lopencv_highgui -lopencv_features2d -lopencv_calib3d -lopencv_ml -lopencv_objdetect -lopencv_video -lopencv_photo -lopencv_videostab -ltegra_hal -lopencv_imgcodecs -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_videoio -L<newly-compiled-Qt-root>/lib -lQt5Quick -lQt5MultimediaWidgets -lQt5Multimedia -lQt5Widgets -lQt5Gui -lQt5Qml -lQt5Network -lQt5Core -lGLESv2 -lc++ -llog -lz -lm -ldl -lc

编辑:尝试自己编译OpenCV,效果不佳。
Edit2:我刚刚看到Petesh的答案:https://stackoverflow.com/a/12920944/9987834
可能是因为我的Qt和OpenCV版本是使用不同的标准库编译的吗?
Edit3:无法正确编译OpenCV,出现这样的错误:

skipping incompatible /usr/local/lib/libopencv_core.a when searching for -lopencv_core

Edit4:由于某种原因,OpenCV完全停止了编译,并给了我以下错误:

In file included from /path/to/opencv-3.2.0/modules/core/src/algorithm.cpp:43:
In file included from /path/to/opencv-3.2.0/modules/core/src/precomp.hpp:84:
In file included from /path/to/opencv-3.2.0/modules/core/include/opencv2/core/hal/intrin.hpp:297:
/path/to/opencv-3.2.0/modules/core/include/opencv2/core/hal/intrin_neon.hpp:285:49: error: expected
      unqualified-id
template <typename T> static inline float16x4_t vld1_f16(const T* ptr)
                                                ^
<ndk-r16b-root>/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/5.0.300080/include/arm_neon.h:7745:24: note:
      expanded from macro 'vld1_f16'
#define vld1_f16(__p0) __extension__ ({ \
                       ^
[ 31%] Built target libwebp
[ 31%] Building CXX object modules/core/CMakeFiles/opencv_core.dir/src/command_line_parser.cpp.o
In file included from /path/to/opencv-3.2.0/modules/core/src/algorithm.cpp:43:
In file included from /path/to/opencv-3.2.0/modules/core/src/precomp.hpp:84:
In file included from /path/to/opencv-3.2.0/modules/core/include/opencv2/core/hal/intrin.hpp:297:
/path/to/opencv-3.2.0/modules/core/include/opencv2/core/hal/intrin_neon.hpp:778:8: error: unknown type
      name 'v_float16x4'; did you mean 'v_float32x4'?
inline v_float16x4 v_load_f16(const short* ptr)
       ^~~~~~~~~~~
       v_float32x4

我的蛋糕(gui)输出在这里:https://pastebin.com/ZBrtizUi

有人知道为什么吗?

0 个答案:

没有答案