Important: Please read the Qt Code of Conduct -

Qt creator + Android + clang

  • Before anything, Hi to everyone. First time posting at this forum.
    I'm having some problems porting existing code to Qt for Android. Downloaded Android SDK + NDK, used it fine. Then downloaded Qt Creator, started porting the App and could get it to work on Android. Kinda. I replaced the gprc part by a mock, and it worked.
    Now, I'm trying to get it to work and it's being quite a mess.

    Compiled the grpc libraries part basing on the grpc Android example. I got it to work. But when linking, I got symbols not found errors, apparently because Qt Creator is using GCC (it shouldn't, it's deprecated on Android NDK long time ago), whereas the grpc example uses clang and both compilers are using different name mangling systems.

    So, I tried to switch the project to clang. It just doesn't work.

    For starters, even when clang is a part of the Android NDK, it doesn't get detected by QT Creator. Fine. Then, even when I add it manually, I dont have an "Android Clang" option like there is for "Android GCC". Fine. I will add it as a compiler manually.

    I added the compiler under tools/kits/compilers:

    I tell Qt Creator that there's a clang at that route, and that it should compile for that architecture (same settings I've used to recompile Qt libraries). Sill don't know where a lot of flags come from (they're not in this pane and can't seem to configure them from here, but w/e).

    Then I configure the kit:

    And I tell Qt Creator that this kit comes with that compiler.

    Next I configure my project to use that kit

    Then I clean, run qmake and when I press build, it builds with plain clang++ (from path, instead of the provided one) and without the target flags (tries to compile for x86_64 and that doesn't work because I have static asserts that catch structures sizes incorrectly configured, namely time_t is 64 bits instead of 32).

    I was able to "force" it to compile with such a compiler setting QMAKE_CXX and adding -target armv7-none-linux-androideabi to QMAKE_CXXFLAGS (awful and kills the multitarget part), but then "I get Relocations in generic ELF", which led me to thing I'm still missing more settings (like -fPIC), but I want to know what I am doing wrong regarding to setting the compiler/kit instead of keeping banging my head against a very hard wall.


  • @MirkoSerra

    Hi and welcome to devnet forums

    You cannot switch the compiler from GCC to CLANG just by adding the compiler.

    All Qt libraries are typically pre-built and simply pulled from a repository during the installation process. The number of different builds is limited. Therefore you cannot simply install Qt libs for a compiler of your preference. You would need to the compiler of your preference and build Qt libs respectively the dynamic libs by using that compiler. When the build was successful you can include this build and use it for building your applications based on Qt libs.

    For instance there are a couple of different prebuilds available on windows, but MinGW 64 bit is not included in the prebuilds and has to be compiled when you decide to requrie a 64 bit build.

    Here are some details for Qt on Android AFAIK nobody has tried to compile Qt on his own. At least it is not reported AFAIK. This does not mean that it is not possible, but guidelines may be missing.

    This is merely a user driven forum and Android is merely implementation driven compared to other parts. Therefore, I would suggest to you that post also in the qt-android forum on google for getting support in building Qt libraries with an additional not directly compiler.

  • @koahnig Thanks, I did recompile QT libs with clang before doing this.

  • @MirkoSerra just in case, you may want to use an "older" NDK that still has GCC provided. See this post for more information.

  • @Pablo-J.-Rogina Thanks. In the NDK I have both compilers. The problem is QT (creator's build system and qt libraries) uses gcc, GRPC uses clang (in line with new Android requirements). Project uses both libraries, so need to compile everything with one compiler. Already compiled Qt libraries with clang. But Qt creator isn't letting me compile the project with clang.

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Did you check whether your NDK's GCC is not just a symlink to clang ?

  • @SGaist It is not, but if it were, I would have no problems. The thing is, symbols differ from one compiler to the other because they're different.

  • Lifetime Qt Champion

    Which version of the NDK are you using ?

Log in to reply