Building a Project in Qt-Creator on Mac for Android

  • I'm having trouble doing an Android build (my first attempt) on my Mac, using c++11 features in QtCreator 2.8, Qt 5.1.2.

    When I build, I get the following errors (this is just a subset) that imply that c++11 features aren't there:

    @../WeightPlates/weightplate.h:41:9: error: 'shared_ptr' does not name a type
    ../WeightPlates/weightplate.h:46:9: error: 'shared_ptr' does not name a type
    ../WeightPlates/weightplate.h:343:7: error: looser throw specifier for 'virtual wException::~wException()'@

    I've had no problem building this natively on the Mac.

    In the project, I've added the following "Additional Arguments:"


    Adding just c++11 resulting in a compilation command-line that specified -std=gnu++0x, which looks like it's the default (in qtbase/mkspecs/android-g++/qmake.conf) If I add the following to "Additional Arguments:"

    @CONFIG+=c++11 QMAKE_CXXFLAGS+=-std=c++11@

    Then the command line contains these two -std arguments: -std=gnu++0x -std=c++11
    And even in that case, I get the same compilation errors.

    The complete compilation line that's generated is:
    @/Volumes/Projects/android-ndk-r8e/toolchains/arm-linux-androideabi-4.7/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-g++ -c -Wno-psabi -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -ffunction-sections -funwind-tables -fstack-protector -fno-short-enums -DANDROID -Wa,--noexecstack -std=gnu++0x -std=c++11 -O0 -g -g -marm -O0 -fno-omit-frame-pointer -Wall -Wno-psabi -W -D_REENTRANT -fPIE -DQT_NO_PRINTER -DQT_NO_PRINTDIALOG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../../qt5-android/qtbase/mkspecs/android-g++ -I../WeightPlates -I../../qt5-android/qtbase/include -I../../qt5-android/qtbase/include/QtWidgets -I../../qt5-android/qtbase/include/QtGui -I../../qt5-android/qtbase/include/QtCore -I. -I. -I../../android-ndk-r8e/sources/cxx-stl/gnu-libstdc++/4.7/include -I../../android-ndk-r8e/sources/cxx-stl/gnu-libstdc++/4.7/libs/armeabi-v7a/include -I../../android-ndk-r8e/platforms/android-9/arch-arm/usr/include -I. -o main.o ../WeightPlates/main.cpp@

    Is c++11 support for cross compilation between Mac and Android available? If so, can anyone advise what I might be doing wrong?



  • No? Nothing? No one? Was it something I said...? Didn't say...? ;)

  • So I just cajoled qmake to generate only -std=c++11, and the compiler didn't complain about it, but it also didn't accept the C++11 features I'm using.

    Anyone have any ideas...?


  • OK, so I figured it out...

    Specifically, the problem was with shared_ptr. For some reason, in the android build environment (in Qt-Creator), you have to explicitly @#include <memory>@

    When building for the Mac native, I didn't have to. Yet, when I did some testing on the command-line to build a quick test on the Mac, I did have to #include <memory>, in, if I remember right, every case. I tried gcc48 and clang++ 4.1.

    Oh, and in case it helps anyone in the future, I found that even after installing gcc48, it would by default use the gcc 4.2.1 header files in /usr/include/c++/4.2.1 So don't assume anything!!!

  • Lifetime Qt Champion

    Hi and thanks for sharing your findings

    For the gcc stuff, did you install gcc_select ? (I didn't tested it yet)

  • I looked for gcc_select, but it looks like it hasn't come with Mac OS X for quite a while. The only alternative I could find was to change the symbolic link from gcc to whatever I wanted to use. Not sure how that influences where to find the include files. Someone claims the gcc executable figures that out (not sure how) and/or there's the -I command-line option and/or the INCLUDE environment variable... though that seems to have been renamed CPATH or CPLUS_INCLUDE_PATH for gcc (been a while since I used that one)


  • Lifetime Qt Champion

    IFAIK It's from macports

  • I looked into it, but apparently it's for the "port select" options of MacPorts:

    bq. gcc_select installs files that allow 'port select' to switch the default version of gcc. It symlinks
    the standard compiler executables in the MacPorts prefix to the selected version.

  • Lifetime Qt Champion

    But should it do what you need ?

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.