Discussion:
Migration from Android.mk to cmake - linking problem
Tsvetan Bogoev
2018-06-15 06:47:18 UTC
Permalink
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
--
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.
To post to this group, send email to android-***@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/6f9f1631-f5de-40aa-8e66-cf8f8acbcb3f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Tsvetan Bogoev
2018-06-15 09:04:46 UTC
Permalink
I am using r17b (also tried r17)
Post by Tsvetan Bogoev
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
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
--
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.
To post to this group, send email to android-***@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/fd1af75a-740d-45ca-b299-3e90fb681040%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Tsvetan Bogoev
2018-06-15 09:05:53 UTC
Permalink
I am using r17b (also tried r17)
--
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.
To post to this group, send email to android-***@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/69d9e21d-df4e-42fb-8661-cbe3576c85c7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Tsvetan Bogoev
2018-06-15 13:02:33 UTC
Permalink
I found what causes the problem, while using cmake ld is called with the
following options:
-plugin /home/myhome/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-
x86_64/bin/../lib64/LLVMgold.so
-plugin-opt=mcpu=generic
-plugin-opt=Os
-plugin-opt=-function-sections
-plugin-opt=-data-sections

when using ndk-build it looks like:
-plugin /home/tsvetan/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-
x86_64/bin/../lib64/LLVMgold.so
-plugin-opt=mcpu=generic

the "-plugin-opt=Os" is missing. So now I am trying to understand why cmake
passes this to ninja an thus link command fails
--
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.
To post to this group, send email to android-***@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/34ce12d2-a85e-4597-b44b-85a5117fa91b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Tsvetan Bogoev
2018-06-15 13:03:28 UTC
Permalink
I found what causes the problem, while using cmake ld is called with the
following options:
-plugin /home/myhome/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-
x86_64/bin/../lib64/LLVMgold.so
-plugin-opt=mcpu=generic
-plugin-opt=Os
-plugin-opt=-function-sections
-plugin-opt=-data-sections

when using ndk-build it looks like:
-plugin /home/myhome/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-
x86_64/bin/../lib64/LLVMgold.so
-plugin-opt=mcpu=generic

the "-plugin-opt=Os" is missing. So now I am trying to understand why cmake
passes this to ninja an thus link command fails
--
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.
To post to this group, send email to android-***@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/e2380fdb-d171-4852-8787-55b1547935a2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...