Changing the default compiler back from Intel C++ Compiler to GCC for x86 targets

Reference number: DPD200248916

Product versions:

  • Intel® C++ Compiler for Android* - Windows* Host
  • Intel® C++ Compiler for Android* - Linux* Host
  • Intel® C++ Compiler for Android* - OS X* Host

Problem description:

After installation of the Intel C++ Compiler for Android the NDK build system will choose the Intel compiler as default compiler for x86 targets. This is due to the way the NDK build system works. By setting the V=1 option you can check which compiler is actually used for compilation. 

%NDK_DIR%\ndk-build V=1 -B APP_ABI=x86
......
C:/Intel/cc_android_14.0.0.014//bin/ia32/icc.exe -Wl,--as-needed -MMD -MP -MF ./obj/local/x86/objs-debug/hello-jni/hello-jni.o.d -ffunction-sections -m32 -O2 -g -DNDEBUG -fomit-frame-pointer -fstrict-aliasing -finline-limit=300 -O0 -UNDEBUG -fno-omit-frame-pointer -fno-strict-aliasing -Ijni -DANDROID -Wa,--noexecstack -Wformat -Werror=format-security -IC:/android-ndk-r9/platforms/android-9/arch-x86/usr/include -c jni/hello-jni.c -o ./obj/local/x86/objs-debug/hello-jni/hello-jni.o

Solution:

Choose one of the options below to use the GCC compiler instead of the Intel compiler. 

  1. Specify the toolchain explicitly like below:
    %NDK_DIR%\ndk-build V=1 -B NDK_TOOLCHAIN=x86-4.6 APP_ABI=x86
    The toolchain x86-4.6 selects the GCC compiler version 4.6 which is the default for the NDK 9. 

    If you want to create a FAT APK file using GCC as compiler for x86 targets use the following command sequence:
    %NDK_DIR%ndk-build V=1 -B NDK_TOOLCHAIN=x86-4.6 APP_ABI=x86
    %NDK_DIR%ndk-build V=1 -B APP_ABI="armeabi armeabi-v7a mips" NDK_APP.local.cleaned_binaries=true 
    
     
    The option NDK_APP.local.cleaned_binaries=true is an internal NDK option to prevent the libs directory to get cleaned up. 
     
  2. Making GCC the default compiler as it was before the installation of the Intel® C++ Compiler for Android requires to change the make files of the NDK build system. 

    The default compiler is selected by the file '%NDK_DIR%/build/core/setup-toolchain.mk'. Open this file in a text editor of your choice and search for the term "ifndef NDK_TOOLCHAIN". For NDK Version 9 this term can be found on line number 28. 
    # Check that we have a toolchain that supports the current ABI.
    # NOTE: If NDK_TOOLCHAIN is defined, we're going to use it.
    #
    ifndef NDK_TOOLCHAIN
        TARGET_TOOLCHAIN_LIST := $(strip $(sort $(NDK_ABI.$(TARGET_ARCH_ABI).toolchains)))
     
        # Filter out the Clang toolchain, so that we can keep GCC as the default
        # toolchain.
        $(foreach _ver,$(LLVM_VERSION_LIST), 
            $(eval TARGET_TOOLCHAIN_LIST := 
                $(filter-out %-clang$(_ver),$(TARGET_TOOLCHAIN_LIST))))
        # Filter out 4.7 and 4.8 which is considered experimental at this moment
        TARGET_TOOLCHAIN_LIST := $(filter-out %4.7 %4.8,$(TARGET_TOOLCHAIN_LIST))
    

     
    You need to add the following two lines directly after the section you see above to filter out ICC while the NDK build system determines the default compiler:
    # Filter out x86-icc so that is will not be default compiler
    TARGET_TOOLCHAIN_LIST := $(filter-out x86-icc%,$(TARGET_TOOLCHAIN_LIST))
    


    The result should look like this:
    # Check that we have a toolchain that supports the current ABI.
    # NOTE: If NDK_TOOLCHAIN is defined, we're going to use it.
    #
    ifndef NDK_TOOLCHAIN
        TARGET_TOOLCHAIN_LIST := $(strip $(sort $(NDK_ABI.$(TARGET_ARCH_ABI).toolchains)))
     
        # Filter out the Clang toolchain, so that we can keep GCC as the default
        # toolchain.
        $(foreach _ver,$(LLVM_VERSION_LIST), 
            $(eval TARGET_TOOLCHAIN_LIST := 
                $(filter-out %-clang$(_ver),$(TARGET_TOOLCHAIN_LIST))))
        # Filter out 4.7 and 4.8 which is considered experimental at this moment
        TARGET_TOOLCHAIN_LIST := $(filter-out %4.7 %4.8,$(TARGET_TOOLCHAIN_LIST))
        # Filter out x86-icc so that is will not be default compiler
        TARGET_TOOLCHAIN_LIST := $(filter-out x86-icc%,$(TARGET_TOOLCHAIN_LIST)
    
For more complete information about compiler optimizations, see our Optimization Notice.