Issues with Building OpenCV for Android using Qt 6.4.2 on Windows 10
-
Hi Guys!
I'm trying to build and use OpenCV for Android in my Qt 6.4.2 project on Windows 10, but I'm running into some issues.
Here’s what I’ve done so far:
I added OpenCV in my project (pro file) like this:
INCLUDEPATH += F:/Asztal/VP/OpenCV-android-sdk/sdk/native/jni/include/ LIBS += \ -L"F:/Asztal/VP/OpenCV-android-sdk/sdk/native/3rdparty/libs/armeabi-v7a/" \ -L"F:/Asztal/VP/OpenCV-android-sdk/sdk/native/libs/armeabi-v7a/" \ -L"F:/Asztal/VP/OpenCV-android-sdk/sdk/native/staticlibs/armeabi-v7a/" \ -lopencv_core \ -lopencv_highgui \ -lopencv_imgproc \ -lopencv_imgcodecs \ -lopencv_features2d \ -lopencv_calib3d
I attempted to use OpenCV functions, like this:
#include <opencv2/opencv.hpp> cv::Mat QImageToCvMat(const QImage &image) { return cv::Mat(image.height(), image.width(), CV_8UC4, (void*)image.constBits(), image.bytesPerLine()).clone(); } QImage CvMatToQImage(const cv::Mat &mat) { return QImage(mat.data, mat.cols, mat.rows, mat.step, QImage::Format_RGBA8888).copy(); } QImage upscaleWithOpenCV(const QImage &image, int newWidth, int newHeight) { cv::Mat mat = QImageToCvMat(image); cv::Mat resizedMat; cv::resize(mat, resizedMat, cv::Size(newWidth, newHeight), 0, 0, cv::INTER_LANCZOS4); return CvMatToQImage(resizedMat); } //using: QLabel *lajos = new QLabel(); QImage betterScaledImage = upscaleWithOpenCV(preview, this->width(), this->height()); lajos->setPixmap(QPixmap::fromImage(betterScaledImage)); lajos->show();
The include is correct because, I didnt get error then. But When I try to rebuild I get these errors:
I’ve tried different approaches, but I haven’t been able to resolve the issue. Has anyone successfully built OpenCV for Android using Qt on Windows? Any advice or guidance would be greatly appreciated!Thanks in advance!
-
@jsulm okay sorry these errors kinda same:
ld: error: undefined symbol: carotene_o4t::isSupportedConfiguration() >>> referenced by arithm.dispatch.cpp >>> arithm.dispatch.cpp.o:(cv::hal::add8u(unsigned char const*, unsigned int, unsigned char const*, unsigned int, unsigned char*, unsigned int, int, int, void*)) in archive F:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a >>> referenced by arithm.dispatch.cpp >>> arithm.dispatch.cpp.o:(cv::hal::add8s(signed char const*, unsigned int, signed char const*, unsigned int, signed char*, unsigned int, int, int, void*)) in archive F:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a
(the path is a little different, because I tried some changes)
-
@Kaguro said in Issues with Building OpenCV for Android using Qt 6.4.2 on Windows 10:
armeabi-v7a
I'm not sure this is the correct ABI. Check the ABI of your Android Qt installation, it is probably v8a. ABIs must match.
-
@Kaguro Then look in the build log for linker warnings: if some libs are incompatible you will get warning.
And as I suggested before: check which libraries provide the symbols which are not found and then check whether you link these libs.
For example carotene_o4t::isSupportedConfiguration seems to come from libtegra_hal (see https://stackoverflow.com/questions/41665655/what-is-carotene-o4t-and-why-does-it-cause-issues-with-compiling-a-program-using). -
@Kaguro said in Issues with Building OpenCV for Android using Qt 6.4.2 on Windows 10:
this can be the problem?
It can if the ABIs do not match.
-
@jsulm
so I try this now:LIBS += \ -L"F:/Asztal/VP/mew/OpenCV-android-sdk/sdk/native/3rdparty/libs/armeabi-v7a/" \ -L"F:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/libs/armeabi-v7a/" \ -L"F:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/staticlibs/armeabi-v7a/" \ -LF:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/staticlibs/armeabi-v7a -lopencv_core \ -LF:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/staticlibs/armeabi-v7a -lopencv_dnn \ -LF:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/staticlibs/armeabi-v7a -lopencv_flann \ -LF:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/staticlibs/armeabi-v7a -lopencv_highgui \ -LF:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/staticlibs/armeabi-v7a -lopencv_gapi \ -LF:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/staticlibs/armeabi-v7a -lopencv_ml \ -LF:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/staticlibs/armeabi-v7a -lopencv_objdetect \ -LF:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/staticlibs/armeabi-v7a -lopencv_photo \ -LF:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/staticlibs/armeabi-v7a -lopencv_imgproc \ -LF:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/staticlibs/armeabi-v7a -lopencv_imgcodecs \ -LF:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/staticlibs/armeabi-v7a -lopencv_features2d \ -LF:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/staticlibs/armeabi-v7a -lopencv_calib3d \ -LF:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/staticlibs/armeabi-v7a -lopencv_video \ -LF:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/staticlibs/armeabi-v7a -lopencv_videoio \ -LF:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/3rdparty/libs/armeabi-v7a -ltegra_hal \ -LF:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/staticlibs/armeabi-v7a -lopencv_stitching \ -LF:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/3rdparty/libs/armeabi-v7a -ltbb
And now I got "only" 15 errors for example:
:-1: error: error: undefined symbol: android_getCpuFeatures
:-1: error: error: undefined symbol: __itt_thread_set_name_ptr__3_0
:-1: error: error: undefined symbol: __itt_string_handle_create_ptr__3_0
(etc..)And it looks like this is from libopencv_core. But I already linked the libopencv_core
-
@jsulm Sorry I am really a beginner and I don't understand exactly what you would ask for.
I just see errors and this is the whole log what I see :C:\Users\Kaguro\AppData\Local\Android\Sdk\ndk\23.1.7779620/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++ -target armv7a-linux-androideabi23 -fno-limit-debug-info -Wl,--exclude-libs,libunwind.a -Wl,-soname,libPoorMans_thatsyou_client_armeabi-v7a.so -Wl,--build-id=sha1 -Wl,--no-undefined -Wl,-z,noexecstack -shared -o libPoorMans_thatsyou_client_armeabi-v7a.so @object_script.libPoorMans_thatsyou_client_armeabi-v7a.so -LF:/Asztal/VP/mew/OpenCV-android-sdk/sdk/native/3rdparty/libs/armeabi-v7a/ -LF:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/libs/armeabi-v7a/ -LF:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/staticlibs/armeabi-v7a/ -LF:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/staticlibs/armeabi-v7a -lopencv_core -lopencv_dnn -lopencv_flann -lopencv_highgui -lopencv_gapi -lopencv_ml -lopencv_objdetect -lopencv_photo -lopencv_imgproc -lopencv_imgcodecs -lopencv_features2d -lopencv_calib3d -lopencv_video -lopencv_videoio -LF:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/3rdparty/libs/armeabi-v7a -ltegra_hal -lopencv_stitching -ltbb D:/Qt/6.4.2/android_armv7/lib/libQt6MultimediaWidgets_armeabi-v7a.so D:/Qt/6.4.2/android_armv7/lib/libQt6Multimedia_armeabi-v7a.so D:/Qt/6.4.2/android_armv7/lib/libQt6Widgets_armeabi-v7a.so D:/Qt/6.4.2/android_armv7/lib/libQt6Gui_armeabi-v7a.so -lEGL D:/Qt/6.4.2/android_armv7/lib/libQt6Network_armeabi-v7a.so D:/Qt/6.4.2/android_armv7/lib/libQt6Core_armeabi-v7a.so -llog -pthread -lGLESv2 -llog -lz -lm -ldl -lc ld: error: undefined symbol: android_getCpuFeatures >>> referenced by system.cpp >>> system.cpp.o:(cv::HWFeatures::initialize()) in archive F:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a ld: error: undefined symbol: __itt_thread_set_name_ptr__3_0 >>> referenced by system.cpp >>> system.cpp.o:(cv::TLSData<cv::(anonymous namespace)::ThreadID>::createDataInstance() const) in archive F:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a ld: error: undefined symbol: __itt_string_handle_create_ptr__3_0 >>> referenced by trace.cpp >>> trace.cpp.o:(cv::utils::trace::details::Region::LocationExtraData::LocationExtraData(cv::utils::trace::details::Region::LocationStaticStorage const&)) in archive F:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a >>> referenced by trace.cpp >>> trace.cpp.o:(cv::utils::trace::details::Region::Impl::leaveRegion(cv::utils::trace::details::TraceManagerThreadLocal&)) in archive F:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a >>> referenced by trace.cpp >>> trace.cpp.o:(cv::utils::trace::details::TraceManager::TraceManager()) in archive F:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a >>> referenced 1 more times ld: error: undefined symbol: __itt_api_version_ptr__3_0 >>> referenced by trace.cpp >>> trace.cpp.o:(cv::utils::trace::details::isITTEnabled()) in archive F:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a ld: error: undefined symbol: __itt_domain_create_ptr__3_0 >>> referenced by trace.cpp >>> trace.cpp.o:(cv::utils::trace::details::isITTEnabled()) in archive F:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a ld: error: undefined symbol: __itt_id_create_ptr__3_0 >>> referenced by trace.cpp >>> trace.cpp.o:(cv::utils::trace::details::Region::Impl::Impl(cv::utils::trace::details::TraceManagerThreadLocal&, cv::utils::trace::details::Region*, cv::utils::trace::details::Region&, cv::utils::trace::details::Region::LocationStaticStorage const&, long long)) in archive F:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a >>> referenced by trace.cpp >>> trace.cpp.o:(cv::utils::trace::details::Region::Impl::registerRegion(cv::utils::trace::details::TraceManagerThreadLocal&)) in archive F:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a ld: error: undefined symbol: __itt_task_begin_ptr__3_0 >>> referenced by trace.cpp >>> trace.cpp.o:(cv::utils::trace::details::Region::Impl::enterRegion(cv::utils::trace::details::TraceManagerThreadLocal&)) in archive F:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a ld: error: undefined symbol: __itt_id_destroy_ptr__3_0 >>> referenced by trace.cpp >>> trace.cpp.o:(cv::utils::trace::details::Region::Impl::~Impl()) in archive F:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a ld: error: undefined symbol: __itt_metadata_add_ptr__3_0 >>> referenced by trace.cpp >>> trace.cpp.o:(cv::utils::trace::details::Region::Impl::leaveRegion(cv::utils::trace::details::TraceManagerThreadLocal&)) in archive F:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a >>> referenced by trace.cpp >>> trace.cpp.o:(cv::utils::trace::details::traceArg(cv::utils::trace::details::TraceArg const&, int)) in archive F:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a >>> referenced by trace.cpp >>> trace.cpp.o:(cv::utils::trace::details::traceArg(cv::utils::trace::details::TraceArg const&, long long)) in archive F:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a >>> referenced 1 more times ld: error: undefined symbol: __itt_task_end_ptr__3_0 >>> referenced by trace.cpp >>> trace.cpp.o:(cv::utils::trace::details::Region::Impl::leaveRegion(cv::utils::trace::details::TraceManagerThreadLocal&)) in archive F:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a ld: error: undefined symbol: __itt_region_begin_ptr__3_0 >>> referenced by trace.cpp >>> trace.cpp.o:(cv::utils::trace::details::TraceManager::TraceManager()) in archive F:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a ld: error: undefined symbol: __itt_region_end_ptr__3_0 >>> referenced by trace.cpp >>> trace.cpp.o:(cv::utils::trace::details::TraceManager::~TraceManager()) in archive F:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a ld: error: undefined symbol: __itt_relation_add_ptr__3_0 >>> referenced by trace.cpp >>> trace.cpp.o:(cv::utils::trace::details::parallelForAttachNestedRegion(cv::utils::trace::details::Region const&)) in archive F:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a ld: error: undefined symbol: __itt_metadata_str_add_ptr__3_0 >>> referenced by trace.cpp >>> trace.cpp.o:(cv::utils::trace::details::traceArg(cv::utils::trace::details::TraceArg const&, char const*)) in archive F:/Asztal/VP/new/OpenCV-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a clang++: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [Makefile:121: libPoorMans_thatsyou_client_armeabi-v7a.so] Error 1 15:40:32: The process "C:\Users\Kaguro\AppData\Local\Android\Sdk\ndk\23.1.7779620\prebuilt\windows-x86_64\bin\make.exe" exited with code 2. 15:40:33: Error while building/deploying project PoorMans_thatsyou_client (kit: Android Qt 6.4.2 Clang armeabi-v7a) 15:40:33: When executing step "Make"
The opencv and the Qt use the same armeabi-v7a.