Discussion:
Compiling shared libraries
Muhui Jiang
2018-11-22 03:25:44 UTC
Permalink
Hi

I am using the ndk-build to build the native shared libraries.

My sample code only consists 8 easy functions. However, I find that the
target libtest.so consists many other functions that are related to ndk
according to their names.

For example, std::__ndk1::char_traits<char>::length(const
std::__ndk1::char_traits<char>::char_type *__s)。 I saw many functions with
the prefix ndk_xxx. I was wondering whether these function has to be here.
Is it possible to generate a libtest.so that only contains the function in
my sample code and package all the other functions that are required by ndk
in the other shared libraries? Many Thanks

Regards
Muhui
--
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/1ff2d584-1ce4-4cfa-8283-d738fb5ffa45%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Alex Cohn
2018-11-24 09:49:42 UTC
Permalink
Apparently, your code uses STL. The default is static linking of STL
runtime, but you can try ANDROID_STL=c++_shared. This will generate a
smaller libtest.so, but you will need to pack the libc++_shared.so (which
is prebiuilt in NDK) into your APK.

BR,
Alex
Post by Muhui Jiang
Hi
I am using the ndk-build to build the native shared libraries.
My sample code only consists 8 easy functions. However, I find that the
target libtest.so consists many other functions that are related to ndk
according to their names.
For example, std::__ndk1::char_traits<char>::length(const
std::__ndk1::char_traits<char>::char_type *__s)。 I saw many functions with
the prefix ndk_xxx. I was wondering whether these function has to be here.
Is it possible to generate a libtest.so that only contains the function in
my sample code and package all the other functions that are required by ndk
in the other shared libraries? Many Thanks
Regards
Muhui
--
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/ee020924-1b50-49cf-9ae4-7f677b10c5b5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
'Dan Albert' via android-ndk
2018-11-26 20:10:07 UTC
Permalink
It looks like your application contains multiple shared libraries using the
STL. If that's the case, you need to do as Alex says and switch to the
shared STL (or no STL). See our docs:
https://developer.android.com/ndk/guides/cpp-support#static_runtimes

If all you want to do is guarantee that only your API is exported from your
library, use a version script or `-fvisibility=hidden` couple with
`__attribute__((visibility("default")))` to control the exported API
surface.
Post by Alex Cohn
Apparently, your code uses STL. The default is static linking of STL
runtime, but you can try ANDROID_STL=c++_shared. This will generate a
smaller libtest.so, but you will need to pack the libc++_shared.so (which
is prebiuilt in NDK) into your APK.
BR,
Alex
Post by Muhui Jiang
Hi
I am using the ndk-build to build the native shared libraries.
My sample code only consists 8 easy functions. However, I find that the
target libtest.so consists many other functions that are related to ndk
according to their names.
For example, std::__ndk1::char_traits<char>::length(const
std::__ndk1::char_traits<char>::char_type *__s)。 I saw many functions with
the prefix ndk_xxx. I was wondering whether these function has to be here.
Is it possible to generate a libtest.so that only contains the function in
my sample code and package all the other functions that are required by ndk
in the other shared libraries? Many Thanks
Regards
Muhui
--
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
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/ee020924-1b50-49cf-9ae4-7f677b10c5b5%40googlegroups.com
<https://groups.google.com/d/msgid/android-ndk/ee020924-1b50-49cf-9ae4-7f677b10c5b5%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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/CAFVaGhu0oreOihtsH0sL0cKc%3DyunEBuvSPOyGPXLc7TQDTiJzg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
AppCoder
2018-11-27 13:31:47 UTC
Permalink
Does the visibility hidden let you mix and match shared libs/STL/exception
handling and run all the statics in parallel?
Post by 'Dan Albert' via android-ndk
It looks like your application contains multiple shared libraries using
the STL. If that's the case, you need to do as Alex says and switch to the
https://developer.android.com/ndk/guides/cpp-support#static_runtimes
If all you want to do is guarantee that only your API is exported from
your library, use a version script or `-fvisibility=hidden` couple with
`__attribute__((visibility("default")))` to control the exported API
surface.
Post by Alex Cohn
Apparently, your code uses STL. The default is static linking of STL
runtime, but you can try ANDROID_STL=c++_shared. This will generate a
smaller libtest.so, but you will need to pack the libc++_shared.so (which
is prebiuilt in NDK) into your APK.
BR,
Alex
Post by Muhui Jiang
Hi
I am using the ndk-build to build the native shared libraries.
My sample code only consists 8 easy functions. However, I find that the
target libtest.so consists many other functions that are related to ndk
according to their names.
For example, std::__ndk1::char_traits<char>::length(const
std::__ndk1::char_traits<char>::char_type *__s)。 I saw many functions with
the prefix ndk_xxx. I was wondering whether these function has to be here.
Is it possible to generate a libtest.so that only contains the function in
my sample code and package all the other functions that are required by ndk
in the other shared libraries? Many Thanks
Regards
Muhui
--
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
<javascript:>.
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/ee020924-1b50-49cf-9ae4-7f677b10c5b5%40googlegroups.com
<https://groups.google.com/d/msgid/android-ndk/ee020924-1b50-49cf-9ae4-7f677b10c5b5%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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/c6887a7d-a66c-4d2e-87bb-8803c201373d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Alex Cohn
2018-12-02 19:39:32 UTC
Permalink
Post by AppCoder
Does the visibility hidden let you mix and match shared libs/STL/exception
handling and run all the statics in parallel?
Mixing STL runtimes is a dangerous and tricky subject, this can be done
correctly, but it's usually easier and safer to switch to single shared STL
runtime. At any rate, this has nothing to do with visibilityI"hidden"). The
most common problem of multiple STL runtimes is when *new* allocates from
one heap, and *delete* operates on another heap. No visibility of API can
help to protect against misuse of this pattern.
Post by AppCoder
Post by 'Dan Albert' via android-ndk
It looks like your application contains multiple shared libraries using
the STL. If that's the case, you need to do as Alex says and switch to the
https://developer.android.com/ndk/guides/cpp-support#static_runtimes
If all you want to do is guarantee that only your API is exported from
your library, use a version script or `-fvisibility=hidden` couple with
`__attribute__((visibility("default")))` to control the exported API
surface.
Post by Alex Cohn
Apparently, your code uses STL. The default is static linking of STL
runtime, but you can try ANDROID_STL=c++_shared. This will generate a
smaller libtest.so, but you will need to pack the libc++_shared.so (which
is prebiuilt in NDK) into your APK.
BR,
Alex
Post by Muhui Jiang
Hi
I am using the ndk-build to build the native shared libraries.
My sample code only consists 8 easy functions. However, I find that
the target libtest.so consists many other functions that are related to ndk
according to their names.
For example, std::__ndk1::char_traits<char>::length(const
std::__ndk1::char_traits<char>::char_type *__s)。 I saw many functions with
the prefix ndk_xxx. I was wondering whether these function has to be here.
Is it possible to generate a libtest.so that only contains the function in
my sample code and package all the other functions that are required by ndk
in the other shared libraries? Many Thanks
Regards
Muhui
--
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
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/ee020924-1b50-49cf-9ae4-7f677b10c5b5%40googlegroups.com
<https://groups.google.com/d/msgid/android-ndk/ee020924-1b50-49cf-9ae4-7f677b10c5b5%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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/ad00e35b-5ca7-4b1a-830c-b839843d74cf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...