Using Qt codes in Android application

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Using Qt codes in Android application

morteza ali Ahmadi
I have an Android application in Android Studio and I want to use Qt C++ codes in my app. I have used pure C++ codes in my android app using cmake and NDK recently and I could interact with my pure C++ and now I want to use Qt C++ codes.

To do this, I have installed Qt with Android capability. After that I copied Qt5.12.7/5.12.7/android_arm64_v8a/lib/*.so and includes file to my Android App /etc/ folder and I created a simple main.cpp and CMakeLists.txt files as follow:

main.cpp

    #include <QString>
    #include <QDebug>
    int main(int argc, char *argv[])
    {
        QString test="HELLO WORLD!";
        qDebug()<<test;
        return 0;
    }

CMakeLists.txt

    cmake_minimum_required(VERSION 3.4.1)
    include_directories(etc/headerFile)
    link_directories(etc/libs)
    add_library(po-lib SHARED main.cpp)
    target_link_libraries(po-lib -lQt5Core)

As seen in the above files, I want to compile a simple Qt C++ code with dependency on libQtCore.so in my Android App, but after compiling the App, the following errors occur:

    Build command failed.
    Error while executing process C:\Users\User1\AppData\Local\Android\Sdk\cmake\3.10.2.4988404\bin\ninja.exe with arguments {-C D:\WorkProjects\Horizon\Ga\po\.cxx\cmake\debug\armeabi-v7a po-lib}
    ninja: Entering directory `D:\WorkProjects\Horizon\Ga\po\.cxx\cmake\debug\armeabi-v7a'
    [1/2] Building CXX object CMakeFiles/po-lib.dir/main.cpp.o
    [2/2] Linking CXX shared library D:\WorkProjects\Horizon\Ga\po\build\intermediates\cmake\debug\obj\armeabi-v7a\libpo-lib.so
    FAILED: D:/WorkProjects/Horizon/Ga/po/build/intermediates/cmake/debug/obj/armeabi-v7a/libpo-lib.so
    cmd.exe /C "cd . && C:\Users\User1\AppData\Local\Android\Sdk\ndk\21.0.6113669\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=armv7-none-linux-androideabi21 --gcc-toolchain=C:/Users/User1/AppData/Local/Android/Sdk/ndk/21.0.6113669/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=C:/Users/User1/AppData/Local/Android/Sdk/ndk/21.0.6113669/toolchains/llvm/prebuilt/windows-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security   -O0 -fno-limit-debug-info  -Wl,--exclude-libs,libgcc_real.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -shared -Wl,-soname,libpo-lib.so -o D:\WorkProjects\Horizon\Ga\po\build\intermediates\cmake\debug\obj\armeabi-v7a\libpo-lib.so CMakeFiles/po-lib.dir/main.cpp.o -LD:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/libs_a  -LD:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/libs_so -lQt5Core -latomic -lm && cd ."
    C:/Users/User1/AppData/Local/Android/Sdk/ndk/21.0.6113669/toolchains/llvm/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld: warning: skipping incompatible D:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/libs_so/libQt5Core.so while searching for Qt5Core
    C:/Users/User1/AppData/Local/Android/Sdk/ndk/21.0.6113669/toolchains/llvm/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld: error: cannot find -lQt5Core
    D:/WorkProjects/Horizon/Ga/po/src/main/cpp/main.cpp:25: error: undefined reference to 'QMessageLogger::debug() const'
    D:/WorkProjects/Horizon/Ga/po/src/main/cpp/main.cpp:25: error: undefined reference to 'QDebug::~QDebug()'
    D:/WorkProjects/Horizon/Ga/po/src/main/cpp/main.cpp:25: error: undefined reference to 'QDebug::~QDebug()'
    D:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/headerFile\QtCore/qstring.h:700: error: undefined reference to 'QString::fromAscii_helper(char const*, int)'
    D:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/headerFile\QtCore/qdebug.h:155: error: undefined reference to 'QDebug::putString(QChar const*, unsigned int)'
    D:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/headerFile\QtCore/qdebug.h:125: error: undefined reference to 'QTextStream::operator<<(char)'
    D:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/headerFile\QtCore/qarraydata.h:59: error: undefined reference to 'qt_assert(char const*, char const*, int)'
    D:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/headerFile\QtCore/qarraydata.h:239: error: undefined reference to 'QArrayData::deallocate(QArrayData*, unsigned int, unsigned int)'
    clang++: error: linker command failed with exit code 1 (use -v to see invocation)
    ninja: build stopped: subcommand failed.

I have used both arm64_v8a and armv7 libs in Qt folders but the same errors appear. How can I solve this linker error (incompatible lib)?

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/3f54c53b-c0d5-4aa9-b401-b8d020b6fbf7%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Using Qt codes in Android application

George Xian
What is your build toolchain? Are you building through QtCreator?

On Friday, March 20, 2020 at 11:32:26 AM UTC+13 [hidden email] wrote:
I have an Android application in Android Studio and I want to use Qt C++ codes in my app. I have used pure C++ codes in my android app using cmake and NDK recently and I could interact with my pure C++ and now I want to use Qt C++ codes.

To do this, I have installed Qt with Android capability. After that I copied Qt5.12.7/5.12.7/android_arm64_v8a/lib/*.so and includes file to my Android App /etc/ folder and I created a simple main.cpp and CMakeLists.txt files as follow:

main.cpp

    #include <QString>
    #include <QDebug>
    int main(int argc, char *argv[])
    {
        QString test="HELLO WORLD!";
        qDebug()<<test;
        return 0;
    }

CMakeLists.txt

    cmake_minimum_required(VERSION 3.4.1)
    include_directories(etc/headerFile)
    link_directories(etc/libs)
    add_library(po-lib SHARED main.cpp)
    target_link_libraries(po-lib -lQt5Core)

As seen in the above files, I want to compile a simple Qt C++ code with dependency on libQtCore.so in my Android App, but after compiling the App, the following errors occur:

    Build command failed.
    Error while executing process C:\Users\User1\AppData\Local\Android\Sdk\cmake\3.10.2.4988404\bin\ninja.exe with arguments {-C D:\WorkProjects\Horizon\Ga\po\.cxx\cmake\debug\armeabi-v7a po-lib}
    ninja: Entering directory `D:\WorkProjects\Horizon\Ga\po\.cxx\cmake\debug\armeabi-v7a'
    [1/2] Building CXX object CMakeFiles/po-lib.dir/main.cpp.o
    [2/2] Linking CXX shared library D:\WorkProjects\Horizon\Ga\po\build\intermediates\cmake\debug\obj\armeabi-v7a\libpo-lib.so
    FAILED: D:/WorkProjects/Horizon/Ga/po/build/intermediates/cmake/debug/obj/armeabi-v7a/libpo-lib.so
    cmd.exe /C "cd . && C:\Users\User1\AppData\Local\Android\Sdk\ndk\21.0.6113669\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=armv7-none-linux-androideabi21 --gcc-toolchain=C:/Users/User1/AppData/Local/Android/Sdk/ndk/21.0.6113669/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=C:/Users/User1/AppData/Local/Android/Sdk/ndk/21.0.6113669/toolchains/llvm/prebuilt/windows-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security   -O0 -fno-limit-debug-info  -Wl,--exclude-libs,libgcc_real.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -shared -Wl,-soname,libpo-lib.so -o D:\WorkProjects\Horizon\Ga\po\build\intermediates\cmake\debug\obj\armeabi-v7a\libpo-lib.so CMakeFiles/po-lib.dir/main.cpp.o -LD:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/libs_a  -LD:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/libs_so -lQt5Core -latomic -lm && cd ."
    C:/Users/User1/AppData/Local/Android/Sdk/ndk/21.0.6113669/toolchains/llvm/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld: warning: skipping incompatible D:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/libs_so/libQt5Core.so while searching for Qt5Core
    C:/Users/User1/AppData/Local/Android/Sdk/ndk/21.0.6113669/toolchains/llvm/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld: error: cannot find -lQt5Core
    D:/WorkProjects/Horizon/Ga/po/src/main/cpp/main.cpp:25: error: undefined reference to 'QMessageLogger::debug() const'
    D:/WorkProjects/Horizon/Ga/po/src/main/cpp/main.cpp:25: error: undefined reference to 'QDebug::~QDebug()'
    D:/WorkProjects/Horizon/Ga/po/src/main/cpp/main.cpp:25: error: undefined reference to 'QDebug::~QDebug()'
    D:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/headerFile\QtCore/qstring.h:700: error: undefined reference to 'QString::fromAscii_helper(char const*, int)'
    D:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/headerFile\QtCore/qdebug.h:155: error: undefined reference to 'QDebug::putString(QChar const*, unsigned int)'
    D:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/headerFile\QtCore/qdebug.h:125: error: undefined reference to 'QTextStream::operator<<(char)'
    D:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/headerFile\QtCore/qarraydata.h:59: error: undefined reference to 'qt_assert(char const*, char const*, int)'
    D:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/headerFile\QtCore/qarraydata.h:239: error: undefined reference to 'QArrayData::deallocate(QArrayData*, unsigned int, unsigned int)'
    clang++: error: linker command failed with exit code 1 (use -v to see invocation)
    ninja: build stopped: subcommand failed.

I have used both arm64_v8a and armv7 libs in Qt folders but the same errors appear. How can I solve this linker error (incompatible lib)?

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/f1e3b888-daa9-4b1c-a388-53bc3fba53ac%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Using Qt codes in Android application

morteza ali Ahmadi
I use NDK build toolchain and I don't use QtCreator for building.

On Friday, March 20, 2020 at 4:08:50 AM UTC+3:30, George Xian wrote:
What is your build toolchain? Are you building through QtCreator?

On Friday, March 20, 2020 at 11:32:26 AM UTC+13 [hidden email] wrote:
I have an Android application in Android Studio and I want to use Qt C++ codes in my app. I have used pure C++ codes in my android app using cmake and NDK recently and I could interact with my pure C++ and now I want to use Qt C++ codes.

To do this, I have installed Qt with Android capability. After that I copied Qt5.12.7/5.12.7/android_arm64_v8a/lib/*.so and includes file to my Android App /etc/ folder and I created a simple main.cpp and CMakeLists.txt files as follow:

main.cpp

    #include <QString>
    #include <QDebug>
    int main(int argc, char *argv[])
    {
        QString test="HELLO WORLD!";
        qDebug()<<test;
        return 0;
    }

CMakeLists.txt

    cmake_minimum_required(VERSION 3.4.1)
    include_directories(etc/headerFile)
    link_directories(etc/libs)
    add_library(po-lib SHARED main.cpp)
    target_link_libraries(po-lib -lQt5Core)

As seen in the above files, I want to compile a simple Qt C++ code with dependency on libQtCore.so in my Android App, but after compiling the App, the following errors occur:

    Build command failed.
    Error while executing process C:\Users\User1\AppData\Local\Android\Sdk\cmake\3.10.2.4988404\bin\ninja.exe with arguments {-C D:\WorkProjects\Horizon\Ga\po\.cxx\cmake\debug\armeabi-v7a po-lib}
    ninja: Entering directory `D:\WorkProjects\Horizon\Ga\po\.cxx\cmake\debug\armeabi-v7a'
    [1/2] Building CXX object CMakeFiles/po-lib.dir/main.cpp.o
    [2/2] Linking CXX shared library D:\WorkProjects\Horizon\Ga\po\build\intermediates\cmake\debug\obj\armeabi-v7a\libpo-lib.so
    FAILED: D:/WorkProjects/Horizon/Ga/po/build/intermediates/cmake/debug/obj/armeabi-v7a/libpo-lib.so
    cmd.exe /C "cd . && C:\Users\User1\AppData\Local\Android\Sdk\ndk\21.0.6113669\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=armv7-none-linux-androideabi21 --gcc-toolchain=C:/Users/User1/AppData/Local/Android/Sdk/ndk/21.0.6113669/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=C:/Users/User1/AppData/Local/Android/Sdk/ndk/21.0.6113669/toolchains/llvm/prebuilt/windows-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security   -O0 -fno-limit-debug-info  -Wl,--exclude-libs,libgcc_real.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -shared -Wl,-soname,libpo-lib.so -o D:\WorkProjects\Horizon\Ga\po\build\intermediates\cmake\debug\obj\armeabi-v7a\libpo-lib.so CMakeFiles/po-lib.dir/main.cpp.o -LD:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/libs_a  -LD:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/libs_so -lQt5Core -latomic -lm && cd ."
    C:/Users/User1/AppData/Local/Android/Sdk/ndk/21.0.6113669/toolchains/llvm/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld: warning: skipping incompatible D:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/libs_so/libQt5Core.so while searching for Qt5Core
    C:/Users/User1/AppData/Local/Android/Sdk/ndk/21.0.6113669/toolchains/llvm/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld: error: cannot find -lQt5Core
    D:/WorkProjects/Horizon/Ga/po/src/main/cpp/main.cpp:25: error: undefined reference to 'QMessageLogger::debug() const'
    D:/WorkProjects/Horizon/Ga/po/src/main/cpp/main.cpp:25: error: undefined reference to 'QDebug::~QDebug()'
    D:/WorkProjects/Horizon/Ga/po/src/main/cpp/main.cpp:25: error: undefined reference to 'QDebug::~QDebug()'
    D:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/headerFile\QtCore/qstring.h:700: error: undefined reference to 'QString::fromAscii_helper(char const*, int)'
    D:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/headerFile\QtCore/qdebug.h:155: error: undefined reference to 'QDebug::putString(QChar const*, unsigned int)'
    D:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/headerFile\QtCore/qdebug.h:125: error: undefined reference to 'QTextStream::operator<<(char)'
    D:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/headerFile\QtCore/qarraydata.h:59: error: undefined reference to 'qt_assert(char const*, char const*, int)'
    D:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/headerFile\QtCore/qarraydata.h:239: error: undefined reference to 'QArrayData::deallocate(QArrayData*, unsigned int, unsigned int)'
    clang++: error: linker command failed with exit code 1 (use -v to see invocation)
    ninja: build stopped: subcommand failed.

I have used both arm64_v8a and armv7 libs in Qt folders but the same errors appear. How can I solve this linker error (incompatible lib)?

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/3be73a2a-d159-4b9b-b9e4-32c3f19ee951%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Using Qt codes in Android application

Andrew Esh-2
In reply to this post by morteza ali Ahmadi
It appears that D:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/libs_so/libQt5Core.so is not "-march=armv7-a" which is the machine type that the compiler is looking for. You said you "copied Qt5.12.7/5.12.7/android_arm64_v8a/lib/*" in the beginning of your message. That is not the same architecture. You need an armv7 version of libQt5Core.so.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/8af3a039-9c3b-4088-b9a1-b222ed28b9a2%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Using Qt codes in Android application

morteza ali Ahmadi
Thanks, but I have tested for armv7 (as I mentioned in the last line of my message), i.e. I have copied both Qt5.12.7/5.12.7/android_arm64_v8a/lib/*.so and Qt5.12.7/5.12.7/android_armv7/lib/*.so to my application and the similar errors appear for both libs architecture (Sorry, the errors in my first message are appeared after using armv7 libs not arm64_v8a). I also built Qt sources for arm64_v8a architecture in Ubuntu and I copied the arm64_v8a libs to my android application but the similar errors appeared as follows:

Build command failed.
Error while executing process /home/user1/Documents/Programs/Android/Sdk/cmake/3.10.2.4988404/bin/ninja with arguments {-C /home/user1/Downloads/PolarisLib/app/.cxx/cmake/debug/arm64-v8a polaris-lib}
ninja: Entering directory `/home/user1/Downloads/PolarisLib/app/.cxx/cmake/debug/arm64-v8a'
[1/2] Building CXX object CMakeFiles/polaris-lib.dir/main.cpp.o
[2/2] Linking CXX shared library /home/user1/Downloads/PolarisLib/app/build/intermediates/cmake/debug/obj/arm64-v8a/libpolaris-lib.so
FAILED: /home/user1/Downloads/PolarisLib/app/build/intermediates/cmake/debug/obj/arm64-v8a/libpolaris-lib.so
: && /home/user1/Documents/Programs/Android/Sdk/ndk/21.0.6113669/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=aarch64-none-linux-android21 --gcc-toolchain=/home/user1/Documents/Programs/Android/Sdk/ndk/21.0.6113669/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/home/user1/Documents/Programs/Android/Sdk/ndk/21.0.6113669/toolchains/llvm/prebuilt/linux-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security   -O0 -fno-limit-debug-info  -Wl,--exclude-libs,libgcc_real.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--fatal-warnings -Wl,--no-undefined -Qunused-arguments -shared -Wl,-soname,libpolaris-lib.so -o /home/user1/Downloads/PolarisLib/app/build/intermediates/cmake/debug/obj/arm64-v8a/libpolaris-lib.so CMakeFiles/polaris-lib.dir/main.cpp.o -L/home/user1/Downloads/PolarisLib/app/src/main/cpp/etc/lib -lQt5Core -latomic -lm && :
/home/user1/Documents/Programs/Android/Sdk/ndk/21.0.6113669/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: skipping incompatible /home/user1/Downloads/PolarisLib/app/src/main/cpp/etc/lib/libQt5Core.so when searching for -lQt5Core
/home/user1/Documents/Programs/Android/Sdk/ndk/21.0.6113669/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: cannot find -lQt5Core
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.


On Friday, March 20, 2020 at 3:49:05 PM UTC+3:30, Andrew Esh wrote:
It appears that D:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/libs_so/libQt5Core.so is not "-march=armv7-a" which is the machine type that the compiler is looking for. You said you "copied Qt5.12.7/5.12.7/android_arm64_v8a/lib/*" in the beginning of your message. That is not the same architecture. You need an armv7 version of libQt5Core.so.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/41d68d3b-f0fa-4307-8647-0facc15c3695%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Using Qt codes in Android application

Andrew Esh-2
In reply to this post by morteza ali Ahmadi
The target architecture has to match the architecture of the libraries you are linking with. You have "clang++ --target=aarch64-none-linux-android21", and "-march=armv7-a", and "D:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/libs_so/libQt5Core.so". I do not know which architecture the library is, but all three of these must match. The error message is saying they do not.

On Thursday, March 19, 2020 at 5:32:26 PM UTC-5, morteza ali Ahmadi wrote:
I have an Android application in Android Studio and I want to use Qt C++ codes in my app. I have used pure C++ codes in my android app using cmake and NDK recently and I could interact with my pure C++ and now I want to use Qt C++ codes.

To do this, I have installed Qt with Android capability. After that I copied Qt5.12.7/5.12.7/android_arm64_v8a/lib/*.so and includes file to my Android App /etc/ folder and I created a simple main.cpp and CMakeLists.txt files as follow:

main.cpp

    #include <QString>
    #include <QDebug>
    int main(int argc, char *argv[])
    {
        QString test="HELLO WORLD!";
        qDebug()<<test;
        return 0;
    }

CMakeLists.txt

    cmake_minimum_required(VERSION 3.4.1)
    include_directories(etc/headerFile)
    link_directories(etc/libs)
    add_library(po-lib SHARED main.cpp)
    target_link_libraries(po-lib -lQt5Core)

As seen in the above files, I want to compile a simple Qt C++ code with dependency on libQtCore.so in my Android App, but after compiling the App, the following errors occur:

    Build command failed.
    Error while executing process C:\Users\User1\AppData\Local\Android\Sdk\cmake\3.10.2.4988404\bin\ninja.exe with arguments {-C D:\WorkProjects\Horizon\Ga\po\.cxx\cmake\debug\armeabi-v7a po-lib}
    ninja: Entering directory `D:\WorkProjects\Horizon\Ga\po\.cxx\cmake\debug\armeabi-v7a'
    [1/2] Building CXX object CMakeFiles/po-lib.dir/main.cpp.o
    [2/2] Linking CXX shared library D:\WorkProjects\Horizon\Ga\po\build\intermediates\cmake\debug\obj\armeabi-v7a\libpo-lib.so
    FAILED: D:/WorkProjects/Horizon/Ga/po/build/intermediates/cmake/debug/obj/armeabi-v7a/libpo-lib.so
    cmd.exe /C "cd . && C:\Users\User1\AppData\Local\Android\Sdk\ndk\21.0.6113669\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=armv7-none-linux-androideabi21 --gcc-toolchain=C:/Users/User1/AppData/Local/Android/Sdk/ndk/21.0.6113669/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=C:/Users/User1/AppData/Local/Android/Sdk/ndk/21.0.6113669/toolchains/llvm/prebuilt/windows-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security   -O0 -fno-limit-debug-info  -Wl,--exclude-libs,libgcc_real.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -shared -Wl,-soname,libpo-lib.so -o D:\WorkProjects\Horizon\Ga\po\build\intermediates\cmake\debug\obj\armeabi-v7a\libpo-lib.so CMakeFiles/po-lib.dir/main.cpp.o -LD:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/libs_a  -LD:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/libs_so -lQt5Core -latomic -lm && cd ."
    C:/Users/User1/AppData/Local/Android/Sdk/ndk/21.0.6113669/toolchains/llvm/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld: warning: skipping incompatible D:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/libs_so/libQt5Core.so while searching for Qt5Core
    C:/Users/User1/AppData/Local/Android/Sdk/ndk/21.0.6113669/toolchains/llvm/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld: error: cannot find -lQt5Core
    D:/WorkProjects/Horizon/Ga/po/src/main/cpp/main.cpp:25: error: undefined reference to 'QMessageLogger::debug() const'
    D:/WorkProjects/Horizon/Ga/po/src/main/cpp/main.cpp:25: error: undefined reference to 'QDebug::~QDebug()'
    D:/WorkProjects/Horizon/Ga/po/src/main/cpp/main.cpp:25: error: undefined reference to 'QDebug::~QDebug()'
    D:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/headerFile\QtCore/qstring.h:700: error: undefined reference to 'QString::fromAscii_helper(char const*, int)'
    D:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/headerFile\QtCore/qdebug.h:155: error: undefined reference to 'QDebug::putString(QChar const*, unsigned int)'
    D:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/headerFile\QtCore/qdebug.h:125: error: undefined reference to 'QTextStream::operator<<(char)'
    D:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/headerFile\QtCore/qarraydata.h:59: error: undefined reference to 'qt_assert(char const*, char const*, int)'
    D:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/headerFile\QtCore/qarraydata.h:239: error: undefined reference to 'QArrayData::deallocate(QArrayData*, unsigned int, unsigned int)'
    clang++: error: linker command failed with exit code 1 (use -v to see invocation)
    ninja: build stopped: subcommand failed.

I have used both arm64_v8a and armv7 libs in Qt folders but the same errors appear. How can I solve this linker error (incompatible lib)?

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/ae380061-6f12-4302-b98c-3aa3bf902bd3%40googlegroups.com.