Trying to build my Qt application for android linking to FFmpeg.
I get the following linker errors on android.
libavformat/hls.c:783: error: undefined reference to 'atof'
libavcodec/ffv1enc.c:476: error: undefined reference to 'log2'
libavcodec/imc.c:472: error: undefined reference to 'log2f'
Following is the list of libraries I trying to link for FFmpeg.
-lavformat -lavcodec -lswscale -lavutil -lavfilter -lswresample -lavdevice -lpostproc -lm -lgnustl_static
What am I missing in the linker options?
I have also set the following to :
CONFIG += c++14
QMAKE_CXXFLAGS_RELEASE += -std=c++1y
QMAKE_CXXFLAGS_DEBUG += -std=c++1y
This is strictly not related to Qt and happens only because those functions are not defined in Android, as discussed in Does Android support log2 and Android ndk can't find atof function, among other places.
You either have to define those functions before including FFmpeg headers or find a library that does this for you.
Related
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?
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:
the test 'HAVE_CPU_NEON_SUPPORT' is performed and validated (executing the check file 'cmake/checks/cpu_neon.cpp')
the test 'HAVE_CPU_FP16_SUPPORT' is performed and validated (executing the check file 'cmake/checks/cpu_fp16.cpp')
and the resulting identified CPU/HW features baseline is identified as "NEON FP16" (see the linked logfile).
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:
the test 'CXX_HAS_MFPU_NEON' is performed and validated
the test 'C_HAS_MFPU_NEON' is performed and validated
the check file 'cmake/checks/fp16.cpp' is ignored.
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.
I'm trying to build poco and cegui libs with crystax ndk(version 10.3.2) using cmake
export ANDROID_NDK=/.../crystax-ndk-10.3.2
cmake -DPOCO_STATIC=ON -DCMAKE_TOOLCHAIN_FILE="../../AndroidBuildToolchain/android.toolchain.cmake" -DANDROID_ABI=x86 -DANDROID_NATIVE_API_LEVEL=21 -DANDROID_TOOLCHAIN_NAME=x86-4.9 ../..
and build my own app with android.mk and I got the same error(using ndk-build):
crystax-ndk-10.3.2/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/i686-linux-android/4.9/../../../../i686-linux-android/bin/ld: error: cannot find -lcrystax
And other link errors from, like these
error: undefined reference to 'sinf'
error: undefined reference to 'cosf'
error: undefined reference to '__getCurrentRuneLocale'
But when i'm trying to build the poco and my project with google NDK it works good. But I have reasons to use crystax. So, can anybody help me to find out the reason of these errors?
I've tried -lm flag for math(sin,cos) lib, but I had the same errors.
I have pre build boost libs for android using standalone tool chain 4.8.
I want to use he following boost libs and added as following in Android.mk
LOCAL_STATIC_LIBRARIES += libboost_atomic \
libboost_date_time \
libboost_exception \
libboost_thread \
libboost_system \
libboost_filesystem
I have adde my own static lib liblocal.a in Android.mk.
I have a mainactivity.cpp file in my JNI folder of android project.
I am including header.h in mainactivity.h. header.h had class declaration for classA which uses boost libs.
while building liblocal.a, I am not getting any link error for boost.
While inclduding header.h in mainactivity.h I am getting the following link error:
../../../3p/boost/android/include/boost/system/error_code.hpp:222: error: undefined reference to 'boost::system::generic_category()'
../../../3p/boost/android/include/boost/system/error_code.hpp:223: error: undefined reference to 'boost::system::generic_category()'
../../../3p/boost/android/include/boost/system/error_code.hpp:224: error: undefined reference to 'boost::system::system_category()'
../../../3p/boost/android/include/boost/system/error_code.hpp:222: error: undefined reference to 'boost::system::generic_category()'
../../../3p/boost/android/include/boost/system/error_code.hpp:223: error: undefined reference to 'boost::system::generic_category()'
../../../3p/boost/android/include/boost/system/error_code.hpp:224: error: undefined reference to 'boost::system::system_category()'
../../../3p/boost/android/include/boost/system/error_code.hpp:224: error: undefined reference to 'boost::system::system_category()'
Thanks,
Birajendu
If liblocal.a depends on functions defined in libboost_foo.a, then it must appear before it in the list of static libraries, i.e.:
LOCAL_STATIC_LIBRARIES += liblocal.a libboost_foo.a # GOOD
Should work, while the following:
LOCAL_STATIC_LIBRARIES += libboost_foo.a liblocal.a # BAD
will not, and result in a link error like the one you described.
A work-around is to use LOCAL_WHOLE_STATIC_LIBRARIES that always forces all content from the listed static libraries to be included in the result (this typically generates bloated binaries, but may be necessary if you have circular dependencies).
Hope this helps.
Solved:
I have added LOCAL_LDLIBS += -L$(RELATIVE_PATH_TO_LIB) -lmylib -lmylib1, this solved this issue.
Where as mylib.a and mylib1.a are my pre build static libs.
I am trying to build my code for h.264 video decoding using hardware decoder(OMX codec) in native code of android 4.0.4 by keeping it in the android source tree. The android source is already built. I am using mm command to build my decoder module.
But when I try to build it I am getting the following error
prebuilt/linux-x86/toolchain/arm-linux-androideabi-4.4.x/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/ld:
out/target/product/generic/obj/SHARED_LIBRARIES/custom_decoder_intermediates/custom_decoder.o:
in function custom_decoder::decode_video():frameworks/base/include/utils/RefBase.h:171:
error: undefined reference to 'android_atomic_dec'
when I explored about it, came to know that android_atomic_dec is defined in cutils/atomic.h
which is in system/core/libcutils and the header at system/core/include/cutils of AOSP 4.0.4.
So I have added this also in my android.mk via LOCAL_C_INCLUDES but still to get the same error.
Can someone help me to solve this ??....
You must add cutils to the linkage stage:
LOCAL_LDLIBS += -L $(path-to-system-libs) -lcutils
If you are building AOSP tree, use instead the following:
LOCAL_SHARED_LIBRARIES += libcutils
Ok, I give up...
I've been trying to compile android's 4.x (x>=1) webkit to bypass the 4.0 bugs.
After a few compilations, of the libwebcore with correct bindings and different namespace, and android.webkit with different namespace and some code fixes to match 4.0 - it compiles, and works, on Android 4.3.
Additional problems came in when trying to run it on 4.0-4.2 - where I found out the libicuuc is incompatible between versions, as versioning occurs in the function names. So the solution is theoretically simple - compile libicuuc statically into the libwebcore, by adding LOCAL_STATIC_LIBRARIES += libicuuc to the Android.mk
This is where hell began: I get errors like error: undefined reference to 'vtable for __cxxabiv1::__si_class_type_info' and error: undefined reference to '__dynamic_cast'.
I tried adding LOCAL_RTTI_FLAG := -frtti but it didn't change anything.
Any ideas?
Thanks!