Hi, I have a problem while linking a release version of a shared library using cmake (gradle/Android studio)
While using Android.mk everything is working as expected - I am compiling a couple of static libraries using optimization level -Oz and LTO (-flto) and the it links fine.
But when I switched to cmake I use the same compilation options the code compiles but it can't be linked. Currently I can not find exact ld but it gives the following error:
arm-linux-androideabi/bin/ld: fatal error: Optimization level must be between 0 and 3
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
I did not managed how to pass this "-v" options
here are some gradle arguments and global flags from gradle
externalNativeBuild {
cmake {
arguments "-DCMAKE_BUILD_TYPE=Release",
"-DANDROID_CPP_FEATURES=rtti exceptions",
"-DANDROID_STL=c++_static",
"-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON"
cppFlags "-v -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -flto"
cFlags "-v -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -flto"
}
}
Also I am not sure how to pass some options to linker only (like -Wl,--exclude-libs=ALL -Wl,--gc-sections) - I tried this
list(APPEND ANDROID_LINKER_FLAGS "-Wl,--exclude-libs=ALL -Wl,--gc-sections --verbose -flto")
I believe that there is something wrong with exact call to ld but since the build does not print it I can not compare it with the some call while using ndk-build/Andorid.mk