Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. "Segmentation fault (core dumped)" error after running executable file on the Android device (using Android Clang (C++,aarch64) compiler)

"Segmentation fault (core dumped)" error after running executable file on the Android device (using Android Clang (C++,aarch64) compiler)

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
qtandroidclang++arm64-v8across-compilingaarch64
7 Posts 2 Posters 2.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    morteza ali ahmadi
    wrote on 30 Mar 2020, 06:43 last edited by
    #1

    Hi, I have a simple Qt code (main.cpp) as follow which I want to run in my Android device:

    #include <QCoreApplication>
    #include <QDebug>
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
        qDebug()<<"The program starts successfully.";
        return a.exec();
    }
    

    1- At first, I have put this code within a Qt console project and I have used qmake to create Makefile. After compiling, Qt just outputs *.apk and *.so files from my project but I need executable output. Here is my project *.pro:

    QT -= gui
    
    CONFIG += c++11 console
    CONFIG -= app_bundle
    
    TEMPLATE = app
    DEFINES += QT_DEPRECATED_WARNINGS
    
    SOURCES += \
            main.cpp
    
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    

    and I have:

    • Java ver 1.8.0_242: /usr/lib/jvm/java-8-openjdk-amd64

    • SDK ver 25.2.5: /home/***/Android/Android/Sdk

    • NDK ver 20.0.5594570: /home/***/Android/Android/Sdk/ndk-bundle

    2- In order to produce executable file, I have used Android Clang (C++,aarch64) compiler in a ubuntu terminal by running this command:

    /home/***/Android/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ \
    -D__ANDROID_API__=21 \
    -target aarch64-none-linux-android \
    -gcc-toolchain /home/***/Android/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64 \
    -fno-limit-debug-info \
    -DANDROID_HAS_WSTRING \
    --sysroot=/home/***/Android/Android/Sdk/ndk-bundle/platforms/android-21/arch-arm64 \
    -isystem /home/***/Android/Android/Sdk/ndk-bundle/sysroot/usr/include/aarch64-linux-android \
    -isystem /home/***/Android/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include \
    -isystem /home/***/Android/Android/Sdk/ndk-bundle/sources/android/support/include \
    -isystem /home/***/Android/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++abi/include \
    -fstack-protector-strong -DANDROID -g -g -std=gnu++11 -Wall -W -D_REENTRANT -fPIC -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_CORE_LIB \
    -I/home/***/Qt5.12.7/5.12.7/android_arm64_v8a/mkspecs/android-clang \
    -I/home/***/Qt5.12.7/5.12.7/android_arm64_v8a/include \
    -I/home/***/Qt5.12.7/5.12.7/android_arm64_v8a/include/QtCore \
    -I/home/***/Android/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include \
    -I/home/***/Android/Android/Sdk/ndk-bundle/sysroot/usr/include \
    -L/home/***/Android/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/21 \
    -L/home/***/Android/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android \
    -L/home/***/Qt5.12.7/5.12.7/android_arm64_v8a/lib \
    main.cpp \
    -lc++ -lc++_shared -lQt5Core \
    -o executableMain 
    

    I have used some of the flags and include directories from Makefile in Step 1. After compiling, I can procude an executable file (executableMain). And also here is the results of file executableMain and file libc++_shared.so and file libQt5Core.so respectively:

    executableMain: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /system/, with debug_info, not stripped
    libc++_shared.so: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, BuildID[sha1]=a9c0aad7747976d255d9ea273f6f4c5003901317, stripped
    libQt5Core.so: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, for GNU/Linux 2.6.28, with debug_info, not stripped
    

    3- Now, I want to run the executableMain file in my Android device using adb shell. So, I have copied libc++_shared.so and libQt5Core.so to /System/lib64/ of my Android device and executableMain to a subfolder of /data/user/0. But after setting permission to executableMain (chmod 777 executableMain), running ./executableMain shows the following error:

    Segmentation fault (core dumped)
    

    How can I solve that?

    J 1 Reply Last reply 30 Mar 2020, 06:46
    0
    • M morteza ali ahmadi
      30 Mar 2020, 06:43

      Hi, I have a simple Qt code (main.cpp) as follow which I want to run in my Android device:

      #include <QCoreApplication>
      #include <QDebug>
      int main(int argc, char *argv[])
      {
          QCoreApplication a(argc, argv);
          qDebug()<<"The program starts successfully.";
          return a.exec();
      }
      

      1- At first, I have put this code within a Qt console project and I have used qmake to create Makefile. After compiling, Qt just outputs *.apk and *.so files from my project but I need executable output. Here is my project *.pro:

      QT -= gui
      
      CONFIG += c++11 console
      CONFIG -= app_bundle
      
      TEMPLATE = app
      DEFINES += QT_DEPRECATED_WARNINGS
      
      SOURCES += \
              main.cpp
      
      qnx: target.path = /tmp/$${TARGET}/bin
      else: unix:!android: target.path = /opt/$${TARGET}/bin
      !isEmpty(target.path): INSTALLS += target
      

      and I have:

      • Java ver 1.8.0_242: /usr/lib/jvm/java-8-openjdk-amd64

      • SDK ver 25.2.5: /home/***/Android/Android/Sdk

      • NDK ver 20.0.5594570: /home/***/Android/Android/Sdk/ndk-bundle

      2- In order to produce executable file, I have used Android Clang (C++,aarch64) compiler in a ubuntu terminal by running this command:

      /home/***/Android/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ \
      -D__ANDROID_API__=21 \
      -target aarch64-none-linux-android \
      -gcc-toolchain /home/***/Android/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64 \
      -fno-limit-debug-info \
      -DANDROID_HAS_WSTRING \
      --sysroot=/home/***/Android/Android/Sdk/ndk-bundle/platforms/android-21/arch-arm64 \
      -isystem /home/***/Android/Android/Sdk/ndk-bundle/sysroot/usr/include/aarch64-linux-android \
      -isystem /home/***/Android/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include \
      -isystem /home/***/Android/Android/Sdk/ndk-bundle/sources/android/support/include \
      -isystem /home/***/Android/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++abi/include \
      -fstack-protector-strong -DANDROID -g -g -std=gnu++11 -Wall -W -D_REENTRANT -fPIC -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_CORE_LIB \
      -I/home/***/Qt5.12.7/5.12.7/android_arm64_v8a/mkspecs/android-clang \
      -I/home/***/Qt5.12.7/5.12.7/android_arm64_v8a/include \
      -I/home/***/Qt5.12.7/5.12.7/android_arm64_v8a/include/QtCore \
      -I/home/***/Android/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include \
      -I/home/***/Android/Android/Sdk/ndk-bundle/sysroot/usr/include \
      -L/home/***/Android/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/21 \
      -L/home/***/Android/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android \
      -L/home/***/Qt5.12.7/5.12.7/android_arm64_v8a/lib \
      main.cpp \
      -lc++ -lc++_shared -lQt5Core \
      -o executableMain 
      

      I have used some of the flags and include directories from Makefile in Step 1. After compiling, I can procude an executable file (executableMain). And also here is the results of file executableMain and file libc++_shared.so and file libQt5Core.so respectively:

      executableMain: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /system/, with debug_info, not stripped
      libc++_shared.so: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, BuildID[sha1]=a9c0aad7747976d255d9ea273f6f4c5003901317, stripped
      libQt5Core.so: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, for GNU/Linux 2.6.28, with debug_info, not stripped
      

      3- Now, I want to run the executableMain file in my Android device using adb shell. So, I have copied libc++_shared.so and libQt5Core.so to /System/lib64/ of my Android device and executableMain to a subfolder of /data/user/0. But after setting permission to executableMain (chmod 777 executableMain), running ./executableMain shows the following error:

      Segmentation fault (core dumped)
      

      How can I solve that?

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 30 Mar 2020, 06:46 last edited by
      #2

      @morteza-ali-ahmadi The APK contains your executable. You can simply deploy it through QtCreator to your device and start.
      "How can I solve that?" - use debugger to see where it crashes and how stack trace looks like (you can post it here).

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      M 1 Reply Last reply 30 Mar 2020, 06:54
      0
      • J jsulm
        30 Mar 2020, 06:46

        @morteza-ali-ahmadi The APK contains your executable. You can simply deploy it through QtCreator to your device and start.
        "How can I solve that?" - use debugger to see where it crashes and how stack trace looks like (you can post it here).

        M Offline
        M Offline
        morteza ali ahmadi
        wrote on 30 Mar 2020, 06:54 last edited by
        #3

        @jsulm I can simply deploy the apk app through QtCreator to my device and start but I want to get the executable output (in Linux without any extension and in windows with *.exe extension). Then I want to run the executable file from adb shell. Because finally, my executable file will be started from another android apk as a external process. So I need a executable format.

        Where can I use debugger? (Because this error is appeared on adb shell of my Android device)

        J 1 Reply Last reply 30 Mar 2020, 07:15
        0
        • M morteza ali ahmadi
          30 Mar 2020, 06:54

          @jsulm I can simply deploy the apk app through QtCreator to my device and start but I want to get the executable output (in Linux without any extension and in windows with *.exe extension). Then I want to run the executable file from adb shell. Because finally, my executable file will be started from another android apk as a external process. So I need a executable format.

          Where can I use debugger? (Because this error is appeared on adb shell of my Android device)

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 30 Mar 2020, 07:15 last edited by
          #4

          @morteza-ali-ahmadi said in "Segmentation fault (core dumped)" error after running executable file on the Android device (using Android Clang (C++,aarch64) compiler):

          Where can I use debugger?

          In QtCreator.

          You can open APK (it is an archive) and extract the executable from there. Keep in mind there will not be any.exe extension as it does not have anything to do with Windows.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          M 2 Replies Last reply 30 Mar 2020, 07:28
          0
          • J jsulm
            30 Mar 2020, 07:15

            @morteza-ali-ahmadi said in "Segmentation fault (core dumped)" error after running executable file on the Android device (using Android Clang (C++,aarch64) compiler):

            Where can I use debugger?

            In QtCreator.

            You can open APK (it is an archive) and extract the executable from there. Keep in mind there will not be any.exe extension as it does not have anything to do with Windows.

            M Offline
            M Offline
            morteza ali ahmadi
            wrote on 30 Mar 2020, 07:28 last edited by
            #5

            @jsulm Thanks, I can extract it but there are some *.so files in lib folder (and also there are some folders like assets, META-INF and ...) and there is no executable file.

            1 Reply Last reply
            0
            • J jsulm
              30 Mar 2020, 07:15

              @morteza-ali-ahmadi said in "Segmentation fault (core dumped)" error after running executable file on the Android device (using Android Clang (C++,aarch64) compiler):

              Where can I use debugger?

              In QtCreator.

              You can open APK (it is an archive) and extract the executable from there. Keep in mind there will not be any.exe extension as it does not have anything to do with Windows.

              M Offline
              M Offline
              morteza ali ahmadi
              wrote on 30 Mar 2020, 08:54 last edited by
              #6

              @jsulm Can you help me?

              J 1 Reply Last reply 30 Mar 2020, 11:31
              0
              • M morteza ali ahmadi
                30 Mar 2020, 08:54

                @jsulm Can you help me?

                J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 30 Mar 2020, 11:31 last edited by
                #7

                @morteza-ali-ahmadi I'm not an Android expert. Maybe somebody else knows more.

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0

                1/7

                30 Mar 2020, 06:43

                • Login

                • Login or register to search.
                1 out of 7
                • First post
                  1/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved