cannot find -lc++ when build android project



  • Hi guys, here's my Environment:

    OS: MacOS 10.14.6
    QT: 5.13.0
    JDK: 1.8.0_221, x86_64 "Java SE 8"
    NDK: android-ndk-r20
    Android SDK: Android Studio 3.5 and updated SDK tools
    

    kit setting:
    0_1567678910475_1727b46d-8ac3-4e0b-9e76-521d9aa55603-image.png

    0_1567678957751_39c12011-1abb-4dfb-8dbc-5016ca1a9422-image.png

    0_1567678990051_647c404b-6c7f-4dd0-812e-760b5e18d960-image.png

    When I followed Creating a Mobile Application, the build was failed with error log:

    18:10:37: Running steps for project android_test...
    18:10:37: Starting: "/Users/oc/Qt5.13.0/5.13.0/android_armv7/bin/qmake" /Users/oc/work/temp/android_test/android_test.pro -spec android-clang CONFIG+=debug CONFIG+=qml_debug
    Info: creating stash file /Users/oc/work/temp/build-android_test-Android_for_armeabi_v7a_Clang_Qt_5_13_0_for_Android_ARMv7-Debug/.qmake.stash
    ../android_test/qml.qrc: Warning: potential duplicate alias detected: 'main.qml'
    18:10:37: The process "/Users/oc/Qt5.13.0/5.13.0/android_armv7/bin/qmake" exited normally.
    18:10:37: Starting: "/Users/oc/android-ndk-r20/prebuilt/darwin-x86_64/bin/make" -f /Users/oc/work/temp/build-android_test-Android_for_armeabi_v7a_Clang_Qt_5_13_0_for_Android_ARMv7-Debug/Makefile qmake_all
    make: Nothing to be done for `qmake_all'.
    18:10:37: The process "/Users/oc/android-ndk-r20/prebuilt/darwin-x86_64/bin/make" exited normally.
    18:10:37: Starting: "/Users/oc/android-ndk-r20/prebuilt/darwin-x86_64/bin/make" -j8
    /Users/oc/android-ndk-r20/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ -c -D__ANDROID_API__=21 -target armv7-none-linux-androideabi -gcc-toolchain /Users/oc/android-ndk-r20/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64 -fno-limit-debug-info -DANDROID_HAS_WSTRING --sysroot=/Users/oc/android-ndk-r20/sysroot -isystem /Users/oc/android-ndk-r20/sysroot/usr/include/arm-linux-androideabi -isystem /Users/oc/android-ndk-r20/sources/cxx-stl/llvm-libc++/include -isystem /Users/oc/android-ndk-r20/sources/android/support/include -isystem /Users/oc/android-ndk-r20/sources/cxx-stl/llvm-libc++abi/include -fstack-protector-strong -DANDROID -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -fno-builtin-memmove -g -g -marm -O0 -std=gnu++11 -Wall -W -D_REENTRANT -fPIC -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_QUICK_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I../android_test -I. -I../../../Qt5.13.0/5.13.0/android_armv7/include -I../../../Qt5.13.0/5.13.0/android_armv7/include/QtQuick -I../../../Qt5.13.0/5.13.0/android_armv7/include/QtGui -I../../../Qt5.13.0/5.13.0/android_armv7/include/QtQml -I../../../Qt5.13.0/5.13.0/android_armv7/include/QtNetwork -I../../../Qt5.13.0/5.13.0/android_armv7/include/QtCore -I. -I../../../Qt5.13.0/5.13.0/android_armv7/mkspecs/android-clang -o main.o ../android_test/main.cpp
    /Users/oc/Qt5.13.0/5.13.0/android_armv7/bin/rcc -name qml ../android_test/qml.qrc -o qrc_qml.cpp
    ../android_test/qml.qrc: Warning: potential duplicate alias detected: 'main.qml'
    /Users/oc/android-ndk-r20/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ -c -D__ANDROID_API__=21 -target armv7-none-linux-androideabi -gcc-toolchain /Users/oc/android-ndk-r20/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64 -fno-limit-debug-info -DANDROID_HAS_WSTRING --sysroot=/Users/oc/android-ndk-r20/sysroot -isystem /Users/oc/android-ndk-r20/sysroot/usr/include/arm-linux-androideabi -isystem /Users/oc/android-ndk-r20/sources/cxx-stl/llvm-libc++/include -isystem /Users/oc/android-ndk-r20/sources/android/support/include -isystem /Users/oc/android-ndk-r20/sources/cxx-stl/llvm-libc++abi/include -fstack-protector-strong -DANDROID -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -fno-builtin-memmove -g -g -marm -O0 -std=gnu++11 -Wall -W -D_REENTRANT -fPIC -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_QUICK_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I../android_test -I. -I../../../Qt5.13.0/5.13.0/android_armv7/include -I../../../Qt5.13.0/5.13.0/android_armv7/include/QtQuick -I../../../Qt5.13.0/5.13.0/android_armv7/include/QtGui -I../../../Qt5.13.0/5.13.0/android_armv7/include/QtQml -I../../../Qt5.13.0/5.13.0/android_armv7/include/QtNetwork -I../../../Qt5.13.0/5.13.0/android_armv7/include/QtCore -I. -I../../../Qt5.13.0/5.13.0/android_armv7/mkspecs/android-clang -o qrc_qml.o qrc_qml.cpp
    /Users/oc/android-ndk-r20/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ -D__ANDROID_API__=21 -target armv7-none-linux-androideabi -gcc-toolchain /Users/oc/android-ndk-r20/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -Wl,--exclude-libs,libunwind.a --sysroot=/Users/oc/android-ndk-r20/platforms/android-21/arch-arm/ -Wl,-soname,libandroid_test.so -Wl,-rpath=/Users/oc/Qt5.13.0/5.13.0/android_armv7/lib -Wl,--no-undefined -Wl,-z,noexecstack -shared -o libandroid_test.so main.o qrc_qml.o   /Users/oc/Qt5.13.0/5.13.0/android_armv7/lib/libQt5Quick.so -L/opt/android/android-ndk-r19c/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a /Users/oc/Qt5.13.0/5.13.0/android_armv7/lib/libQt5Gui.so /Users/oc/Qt5.13.0/5.13.0/android_armv7/lib/libQt5Qml.so /Users/oc/Qt5.13.0/5.13.0/android_armv7/lib/libQt5Network.so /Users/oc/Qt5.13.0/5.13.0/android_armv7/lib/libQt5Core.so -lGLESv2  -L/Users/oc/android-ndk-r20/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a /Users/oc/android-ndk-r20/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++.so.21 -llog -lz -lm -ldl -lc
    /Users/oc/android-ndk-r20/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lc++
    clang++: error: linker command failed with exit code 1 (use -v to see invocation)
    make: *** [libandroid_test.so] Error 1
    18:10:38: The process "/Users/oc/android-ndk-r20/prebuilt/darwin-x86_64/bin/make" exited with code 2.
    Error while building/deploying project android_test (kit: Android for armeabi-v7a (Clang Qt 5.13.0 for Android ARMv7))
    When executing step "Make"
    

    I don't know if I make the NDK right, cause I never see NDK with android-clang toolchain from android-getting-started.

    Any advice would be appriciated!


  • Moderators



  • Thanks a lot! That's the solution~

    @albertino said in What's the problem? android compile error:

    The error: cannot find -lc++ using ndk r20 can be solved like this:
    https://codereview.qt-project.org/c/qt/qtbase/+/264903/9/mkspecs/android-clang/qmake.conf#34

    For example to compile for android armv7 ndk r20, locate the file:
    C:\Qt\5.13.0\android_armv7\mkspecs\android-clang\qmake.conf
    and add the missing -nostdlib++
    for android x86 (i use this for emulator), locate the file:
    C:\Qt\5.13.0\android_x86\mkspecs\android-clang\qmake.conf

    For error: Execution failed for task ':compileDebugAidl'
    locate the file on your build directory, mine is: C:\dev_qt\experiments\build-test_qt_5_13_0_ARMv7-Release\android-build\gradle.properties and change androidBuildToolsVersion
    from: androidBuildToolsVersion=29.0.0
    to: androidBuildToolsVersion=28.0.3


Log in to reply