Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android CMake build adding no-exceptions and no-rtti by default

I'm attempting to convert an existing Android.mk based build to CMake and I'm having difficulty building CPP code with exceptions and rtti. The cpp build command generated contains -fno-exceptions and -fno-rtti by default. Adding them as ANDROID_CPP_FEATURES or as cppFlags only appends them to the build command after the default options and the build still fails.

I've searched quite a bit and aside from the few pages pertaining to CMake on Android, I get mostly old Android.mk results from the search.

There is nothing special in any of the CMakeLists.txt file, nothing that would add those options as I can tell.

None of the uncommented options below work.

build.gradle:

    externalNativeBuild {
        cmake {
            arguments '-DANDROID_TOOLCHAIN=gcc',
                       '-DANDROID_PLATFORM=android-19',
                     //  '-DANDROID_STL_FORCE_FEATURES=ON',
                       '-DANDROID_STL=gnustl_static'
                     //'-DANDROID_CPP_FEATURES=rtti'
                     //'-DANDROID_CPP_FEATURES=exceptions',

            cppFlags "-fexceptions -frtti"
            targets  'library2'
        }

    }

Options in build command:

   <removed content> -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -fno-exceptions -fno-rtti -frtti -fexceptions -frtti -O2 -DNDEBUG  -fPIC -MD -MT <additional content>
like image 895
Gary Bak Avatar asked Jan 21 '26 17:01

Gary Bak


1 Answers

With the NDK toolchain r13b I'm using this combination in gradle. The part that through me off was that repeating -DANDROID_CPP_FEATURES overwrites itself and you need a space not a comma between exceptions and rtti.

externalNativeBuild {
    cmake {
         cppFlags '-std=c++11'
         arguments '-DANDROID_TOOLCHAIN=clang',
                 '-DANDROID_PLATFORM=android-19',
                 '-DANDROID_STL=gnustl_static',
                 '-DANDROID_ARM_NEON=TRUE',
                 '-DANDROID_CPP_FEATURES=exceptions rtti'
    }
}
like image 92
Cameron Lowell Palmer Avatar answered Jan 24 '26 08:01

Cameron Lowell Palmer