Discussion:
Dynamically linking against libc++ doesn't work in NDK r14b
(too old to reply)
Andreas Falkenhahn
2018-03-26 12:00:54 UTC
Permalink
I'm compiling a shared object using NDK r14b which uses C++11 and I'm linking dynamically against libc++. However, when dlopen()ing this shared object, I get the following error message:

dlopen failed: library "libc++_shared.so" not found

When I statically link against libc++ it's working fine. Isn't dynamically linking against libc++ supported?
--
Best regards,
Andreas Falkenhahn mailto:***@falkenhahn.com
--
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/1808181614.20180326140054%40falkenhahn.com.
For more options, visit https://groups.google.com/d/optout.
'Ryan Prichard' via android-ndk
2018-03-26 20:37:06 UTC
Permalink
Post by Andreas Falkenhahn
Isn't dynamically linking against libc++ supported?
Yes, that is supported.

What version of Android do you see this problem with?

There's a known issue affecting versions older than Android 4.3, documented
online:

*Shared runtimes*
Post by Andreas Falkenhahn
If your app targets a version of Android earlier than Android 4.3 (Android
API level 18), and you use the shared library variant of a given C++
runtime, you must load the shared library before any other library that
depends on it.
Rather than managing this yourself, we recommend using ReLinker
Post by Andreas Falkenhahn
<https://github.com/KeepSafe/ReLinker>.
https://developer.android.com/ndk/guides/cpp-support.html#shared_runtimes

This problem can be fixed by calling loadLibrary() on libc++_shared.so
first, then calling it on your app's shared library.

-Ryan
Post by Andreas Falkenhahn
I'm compiling a shared object using NDK r14b which uses C++11 and I'm
linking dynamically against libc++. However, when dlopen()ing this shared
dlopen failed: library "libc++_shared.so" not found
When I statically link against libc++ it's working fine. Isn't dynamically
linking against libc++ supported?
--
Best regards,
--
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/1808181614.20180326140054%40falkenhahn.com.
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/CALgsJzkrKwSH8gBG%2BPUDJ4j2kYO7XJsSqW2YxjcJnBW521uDWQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Andreas Falkenhahn
2018-03-26 22:07:05 UTC
Permalink
Post by 'Ryan Prichard' via android-ndk
Yes, that is supported.
What version of Android do you see this problem with?
Shared runtimes
If your app targets a version of Android earlier than Android 4.3
(Android API level 18), and you use the shared library variant of a
given C++ runtime, you must load the shared library before any other library that depends on it.
Rather than managing this yourself, we recommend using ReLinker.
https://developer.android.com/ndk/guides/cpp-support.html#shared_runtimes
This problem can be fixed by calling loadLibrary() on
libc++_shared.so first, then calling it on your app's shared library.
Weird, I get the error on Android O. But since it works when linking
statically it's not that much of a problem. Still weird, though.
--
Best regards,
Andreas Falkenhahn mailto:***@falkenhahn.com
--
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/1297345461.20180327000705%40falkenhahn.com.
For more options, visit https://groups.google.com/d/optout.
'Ryan Prichard' via android-ndk
2018-03-26 23:01:45 UTC
Permalink
The NDK's libc++_shared.so needs to be bundled in an APK's lib/<abi>
directories, alongside other shared libraries. Maybe you're not including
it?

-Ryan
Post by 'Ryan Prichard' via android-ndk
Post by 'Ryan Prichard' via android-ndk
Yes, that is supported.
What version of Android do you see this problem with?
There's a known issue affecting versions older than Android 4.3,
Shared runtimes
If your app targets a version of Android earlier than Android 4.3
(Android API level 18), and you use the shared library variant of a
given C++ runtime, you must load the shared library before any other
library that depends on it.
Post by 'Ryan Prichard' via android-ndk
Rather than managing this yourself, we recommend using ReLinker.
https://developer.android.com/ndk/guides/cpp-support.html#
shared_runtimes
Post by 'Ryan Prichard' via android-ndk
This problem can be fixed by calling loadLibrary() on
libc++_shared.so first, then calling it on your app's shared library.
Weird, I get the error on Android O. But since it works when linking
statically it's not that much of a problem. Still weird, though.
--
Best regards,
--
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/1297345461.20180327000705%40falkenhahn.com.
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/CALgsJz%3DKDsi23RPpyNz%2B4URybjKNg6F9ZzVbxn8qgi-x1XU2OQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Andreas Falkenhahn
2018-03-27 09:38:38 UTC
Permalink
Post by 'Ryan Prichard' via android-ndk
The NDK's libc++_shared.so needs to be bundled in an APK's
lib/<abi> directories, alongside other shared libraries. Maybe you're not including it?
Yes, that was the problem. I didn't know that I had to include
the shared lib in the APK. I thought it would use a one
provided by the system. Works now, thanks.
--
Best regards,
Andreas Falkenhahn mailto:***@falkenhahn.com
--
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/362578388.20180327113838%40falkenhahn.com.
For more options, visit https://groups.google.com/d/optout.
'Dan Albert' via android-ndk
2018-03-27 18:44:04 UTC
Permalink
I thought it would use a one provided by the system.
That's the case for most NDK libraries, but in the case of the C++ stdlib
it works out for the best to bundle it with the app. You wouldn't want to
be locked out of C++17 just because you're supporting devices from 2016 :)
Post by 'Ryan Prichard' via android-ndk
The NDK's libc++_shared.so needs to be bundled in an APK's
lib/<abi> directories, alongside other shared libraries. Maybe you're
not including it?
Yes, that was the problem. I didn't know that I had to include
the shared lib in the APK. I thought it would use a one
provided by the system. Works now, thanks.
--
Best regards,
--
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/362578388.20180327113838%40falkenhahn.com
.
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/CAFVaGhtOE-7U-jPVtBeE5Dd1V2KjkQd9J8po-KQenfzDvfTEZg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Alexis Barra
2018-09-06 23:18:55 UTC
Permalink
Hey Dan,

I don't understand why this library works in a different way. Could you
explain it? or maybe point me a resource to read to understand the reason.

Thanks!
Alexis
I thought it would use a one provided by the system.
That's the case for most NDK libraries, but in the case of the C++ stdlib
it works out for the best to bundle it with the app. You wouldn't want to
be locked out of C++17 just because you're supporting devices from 2016 :)
Post by 'Ryan Prichard' via android-ndk
Post by 'Ryan Prichard' via android-ndk
The NDK's libc++_shared.so needs to be bundled in an APK's
lib/<abi> directories, alongside other shared libraries. Maybe you're
not including it?
Yes, that was the problem. I didn't know that I had to include
the shared lib in the APK. I thought it would use a one
provided by the system. Works now, thanks.
--
Best regards,
--
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/362578388.20180327113838%40falkenhahn.com
.
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/4eaf44d1-0223-49a2-9f21-cf8800f89fe9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Ray Donnelly
2018-09-07 01:54:36 UTC
Permalink
You do not want there end users device dictating what c++ language
specification you can use in your application so you should bundle the ndk
DSO with your app. That way the ndk dictates this aspect.
Post by Alexis Barra
Hey Dan,
I don't understand why this library works in a different way. Could you
explain it? or maybe point me a resource to read to understand the reason.
Thanks!
Alexis
I thought it would use a one provided by the system.
That's the case for most NDK libraries, but in the case of the C++ stdlib
it works out for the best to bundle it with the app. You wouldn't want to
be locked out of C++17 just because you're supporting devices from 2016 :)
Post by 'Ryan Prichard' via android-ndk
Post by 'Ryan Prichard' via android-ndk
The NDK's libc++_shared.so needs to be bundled in an APK's
lib/<abi> directories, alongside other shared libraries. Maybe you're
not including it?
Yes, that was the problem. I didn't know that I had to include
the shared lib in the APK. I thought it would use a one
provided by the system. Works now, thanks.
--
Best regards,
--
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/362578388.20180327113838%40falkenhahn.com
.
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
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/4eaf44d1-0223-49a2-9f21-cf8800f89fe9%40googlegroups.com
<https://groups.google.com/d/msgid/android-ndk/4eaf44d1-0223-49a2-9f21-cf8800f89fe9%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/CAOYw7dsF7j4zqVpQ22-7VdB-Zn7CpTer4GP1s%3DOWkmUbW%2BKk%3Dw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Loading...