Exceptions and RTTI using CMake and ExternalNativeBuild

922 views
Skip to first unread message

Cameron Lowell Palmer

unread,
Jan 26, 2017, 10:32:06 AM1/26/17
to android-ndk
It seems that the officially documented method of enabling exceptions and rtti doesn't work. Is that a known bug?

arguments "-DANDROID_ARM_NEON=TRUE", "-DANDROID_CPP_FEATURES=exceptions", "-DANDROID_CPP_FEATURES=rtti"

Doesn't work. Checking the build options -fno-exceptions and -fno-rtti are injected into the call to clang++.

By adding the request for exceptions and rtti to the cppFlags option I end up with both no-exceptions and exceptions, but it works.
cppFlags "-std=c++11", "-fexceptions"

Finally, these additions to the CMakeLists.txt build script don't do anything. Only cppFlags seems to work.

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_EXTENSIONS ON)

/Users/palmerc/Development/android-ndk/android-ndk-r13b/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++  -target i686-none-linux-android -gcc-toolchain /Users/palmerc/Development/android-ndk/android-ndk-r13b/toolchains/x86-4.9/prebuilt/darwin-x86_64 --sysroot=/Users/palmerc/Development/android-ndk/android-ndk-r13b/platforms/android-19/arch-x86 -fPIC -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -fno-exceptions -fno-rtti -frtti -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -fno-exceptions -fno-rtti -frtti -std=c++11 -fexceptions -O0 -fno-limit-debug-info -O0 -fno-limit-debug-info  -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libavtracker.so -o /Users/palmerc/Development/NextLevel/trunk/apps/build/intermediates/cmake/debug/obj/x86/libavtracker.so CMakeFiles/avtracker.dir/AVTracker-jni.cpp.o CMakeFiles/avtracker.dir/AVTrackerConfiguration.cpp.o CMakeFiles/avtracker.dir/avtracker/AVTracker.cpp.o CMakeFiles/avtracker.dir/avtracker/algorithm/BaseAnalysisAlgorithm.cpp.o CMakeFiles/avtracker.dir/avtracker/utils/PgmLoader.cpp.o  -llog -ljnigraphics -lm "/Users/palmerc/Development/android-ndk/android-ndk-r13b/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86/libgnustl_static.a"

Dan Albert

unread,
Jan 26, 2017, 12:38:35 PM1/26/17
to android-ndk
> "-DANDROID_CPP_FEATURES=exceptions", "-DANDROID_CPP_FEATURES=rtti"

AIUI this doesn't append to ANDROID_CPP_FEATURES, it overwrites. You want `-DANDROID_CPP_FEATURES="rtti exceptions"` I think. Do our docs say to do it the way you've shown?

FYI, exceptions and rtti are on by default starting with NDK r14 (currently in beta).

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+unsubscribe@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/af6b3fe3-efe0-4683-90bc-48054b779e24%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Cameron Lowell Palmer

unread,
Jan 26, 2017, 2:20:51 PM1/26/17
to android-ndk
Actually there are contradictions, other documents make no mention of ANDROID_CPP_FEATURES. This worked for me:

externalNativeBuild {
cmake {
cppFlags '-std=c++11', '-fexceptions', '-frtti'
arguments '-DANDROID_TOOLCHAIN=clang',
'-DANDROID_STL=gnustl_static',
'-DANDROID_ARM_NEON=TRUE'
}
}

This page mentions the ANDROID_CPP_FEATURES, but another says use cppFlags. Confusing.


On Thursday, January 26, 2017 at 6:38:35 PM UTC+1, Dan Albert wrote:
> "-DANDROID_CPP_FEATURES=exceptions", "-DANDROID_CPP_FEATURES=rtti"

AIUI this doesn't append to ANDROID_CPP_FEATURES, it overwrites. You want `-DANDROID_CPP_FEATURES="rtti exceptions"` I think. Do our docs say to do it the way you've shown?

FYI, exceptions and rtti are on by default starting with NDK r14 (currently in beta).
On Thu, Jan 26, 2017 at 12:01 AM, Cameron Lowell Palmer <cameron...@gmail.com> wrote:
It seems that the officially documented method of enabling exceptions and rtti doesn't work. Is that a known bug?

arguments "-DANDROID_ARM_NEON=TRUE", "-DANDROID_CPP_FEATURES=exceptions", "-DANDROID_CPP_FEATURES=rtti"

Doesn't work. Checking the build options -fno-exceptions and -fno-rtti are injected into the call to clang++.

By adding the request for exceptions and rtti to the cppFlags option I end up with both no-exceptions and exceptions, but it works.
cppFlags "-std=c++11", "-fexceptions"

Finally, these additions to the CMakeLists.txt build script don't do anything. Only cppFlags seems to work.

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_EXTENSIONS ON)

/Users/palmerc/Development/android-ndk/android-ndk-r13b/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++  -target i686-none-linux-android -gcc-toolchain /Users/palmerc/Development/android-ndk/android-ndk-r13b/toolchains/x86-4.9/prebuilt/darwin-x86_64 --sysroot=/Users/palmerc/Development/android-ndk/android-ndk-r13b/platforms/android-19/arch-x86 -fPIC -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -fno-exceptions -fno-rtti -frtti -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -fno-exceptions -fno-rtti -frtti -std=c++11 -fexceptions -O0 -fno-limit-debug-info -O0 -fno-limit-debug-info  -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libavtracker.so -o /Users/palmerc/Development/NextLevel/trunk/apps/build/intermediates/cmake/debug/obj/x86/libavtracker.so CMakeFiles/avtracker.dir/AVTracker-jni.cpp.o CMakeFiles/avtracker.dir/AVTrackerConfiguration.cpp.o CMakeFiles/avtracker.dir/avtracker/AVTracker.cpp.o CMakeFiles/avtracker.dir/avtracker/algorithm/BaseAnalysisAlgorithm.cpp.o CMakeFiles/avtracker.dir/avtracker/utils/PgmLoader.cpp.o  -llog -ljnigraphics -lm "/Users/palmerc/Development/android-ndk/android-ndk-r13b/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86/libgnustl_static.a"

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.

Dan Albert

unread,
Jan 26, 2017, 2:34:30 PM1/26/17
to android-ndk, Adarsh Fernando
+adarshf, could you take a look and see if there's some clarification needed in the docs?

To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+unsubscribe@googlegroups.com.

To post to this group, send email to andro...@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.

Cameron Lowell Palmer

unread,
Jan 30, 2017, 3:13:25 PM1/30/17
to android-ndk
So to be clear the developer page discusses ANDROID_CPP_FEATURES and says there is the possibility of exceptions and rtti but provides no example. I have seen such general confusion on this issue that people just pass it via cppFlags. In any case it is weird to see the resulting call to clang has -fno-exceptions -fexceptions and -fno-rtti -frtti.

Seems this should be cleared up in the docs at least and maybe fix the contradictory command-line flags.

On Thursday, January 26, 2017 at 6:38:35 PM UTC+1, Dan Albert wrote:
> "-DANDROID_CPP_FEATURES=exceptions", "-DANDROID_CPP_FEATURES=rtti"

AIUI this doesn't append to ANDROID_CPP_FEATURES, it overwrites. You want `-DANDROID_CPP_FEATURES="rtti exceptions"` I think. Do our docs say to do it the way you've shown?

FYI, exceptions and rtti are on by default starting with NDK r14 (currently in beta).
On Thu, Jan 26, 2017 at 12:01 AM, Cameron Lowell Palmer <cameron...@gmail.com> wrote:
It seems that the officially documented method of enabling exceptions and rtti doesn't work. Is that a known bug?

arguments "-DANDROID_ARM_NEON=TRUE", "-DANDROID_CPP_FEATURES=exceptions", "-DANDROID_CPP_FEATURES=rtti"

Doesn't work. Checking the build options -fno-exceptions and -fno-rtti are injected into the call to clang++.

By adding the request for exceptions and rtti to the cppFlags option I end up with both no-exceptions and exceptions, but it works.
cppFlags "-std=c++11", "-fexceptions"

Finally, these additions to the CMakeLists.txt build script don't do anything. Only cppFlags seems to work.

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_EXTENSIONS ON)

/Users/palmerc/Development/android-ndk/android-ndk-r13b/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++  -target i686-none-linux-android -gcc-toolchain /Users/palmerc/Development/android-ndk/android-ndk-r13b/toolchains/x86-4.9/prebuilt/darwin-x86_64 --sysroot=/Users/palmerc/Development/android-ndk/android-ndk-r13b/platforms/android-19/arch-x86 -fPIC -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -fno-exceptions -fno-rtti -frtti -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -fno-exceptions -fno-rtti -frtti -std=c++11 -fexceptions -O0 -fno-limit-debug-info -O0 -fno-limit-debug-info  -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libavtracker.so -o /Users/palmerc/Development/NextLevel/trunk/apps/build/intermediates/cmake/debug/obj/x86/libavtracker.so CMakeFiles/avtracker.dir/AVTracker-jni.cpp.o CMakeFiles/avtracker.dir/AVTrackerConfiguration.cpp.o CMakeFiles/avtracker.dir/avtracker/AVTracker.cpp.o CMakeFiles/avtracker.dir/avtracker/algorithm/BaseAnalysisAlgorithm.cpp.o CMakeFiles/avtracker.dir/avtracker/utils/PgmLoader.cpp.o  -llog -ljnigraphics -lm "/Users/palmerc/Development/android-ndk/android-ndk-r13b/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86/libgnustl_static.a"

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages