Reputation: 1477
I am trying to compile a program using Qt and OpenCV for arm64-v8a I created a kit to use an arm64-v8a version of Qt, but I get tons of undefined reference errors
I have compiled Qt using the following parameters :
./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
Then I added 2 compilers, the first for C and the second for C++ :
<ndk-r16b-root>/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
with ABI : <custom> arm-linux-android-elf-64-bit
<ndk-r16b-root>/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++
with ABI : <custom> arm-linux-android-elf-64-bit
I cloned the auto-detected kit for this version of Qt and used the following settings :
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
Other fields are left empty/by default
My .pro file looks like this :
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
The OpenCV-android-sdk folder comes from here using 3.2.0 Android pack.
When I try to compile, I get tons of undefined references like the followings :
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*)'
The actual linker command used (where errors happen) is :
<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
Edit: tried to compile OpenCV myself, does not work better.
Edit2: I just saw Petesh's answer there: https://stackoverflow.com/a/12920944/9987834
Could this be because my version of Qt and OpenCV have been compiled using different standard libraries?
Edit3: Cannot manage to compile OpenCV correctly, I get errors like this one:
skipping incompatible /usr/local/lib/libopencv_core.a when searching for -lopencv_core
Edit4: For some reason, OpenCV stopped compiling at all, giving me errors like these:
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
My cake (gui) output is here : https://pastebin.com/ZBrtizUi
Does anyone have an idea why?
Upvotes: 2
Views: 1512
Reputation: 11
Even if it is a late reply, my comment might help another user updating a deprecated Android project...
Here is my typed CMake command (configured variables are detailled in the linked logfiles):
cmake ${OPENCV_CMAKEFILE} -DCMAKE_TOOLCHAIN_FILE=${ANDROID_TOOLCHAIN_FILE} -DANDROID_NDK=${ANDROID_NDK_PATH} -DANDROID_NATIVE_API_LEVEL=android-25 -DBUILD_JAVA=OFF -DBUILD_ANDROID_EXAMPLES=ON -DBUILD_ANDROID_PROJECTS=ON-DANDROID_STL=c++_static -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX:PATH=${OPENCV_INSTALL_PATH} -DANDROID_ABI=arm64-v8a -DCMAKE_BUILD_TYPE=Release
1. With your settings, when FP16 support is enabled using OpenCV 4.5.3, CMake logs indicates that:
Finally, the libraries and example applications are successfully built.
2. With your settings, when FP16 support is enabled using OpenCV 3.2.0, CMake logs indicates that:
Finally, the libraries and example applications are not successfully built (with the same errors you described). I linked typed commands and both CMake configuration logs and compilation error logs. I finally disabled FP16 support and rebuilt OpenCV 3.2.0 successfully. Prebuilts are accessible here.
From my investigation, it appears that some progress on FP16 compiler support for OpenCV has been integrated (reviewed and merged) following the release 3.2.0. This merge from June 21 is the latest work on this matter, a comment from @alalek introduces some previous pull requests.
Upvotes: 1