dec1/Boost-for-Android

What STL were the prebuilt libraries built with?

Closed this issue · 4 comments

Please specify whether it was libc++, gnustl, etc. as well as whether it was the shared or static version of the library.

dec1 commented

clang (llvm) - as of ndk 16 google no longer supports gcc.
shared

I've added a note to the readme. Thanks for pointing this out

You misunderstand me. It is important for Android projects to use a single STL among all dependencies, and that this STL be shared if more than one dependency uses it. See here. This is different from the compiler/toolchain used (llvm). I suspect you did not use libc++ because that is what my other dependencies used and I had issues with my app until I built boost myself from source using shared libc++.

dec1 commented

Sorry, I should have been more clear.

Passing "--stdlibs=llvm" (as I did to create the prebuilt binaries) not only uses the llvm/clang toolchain but also links to their standard library (libc++_shared.so).

They key lines in he build_boosts.sh script are:

register_var_option "--stdlibs=<list>" STDLIBS

for STDLIB in $STDLIBS
    build_boost_for_abi $ABI "$BUILD_DIR/$ABI/$STDLIB" "$STDLIB"
build_boost_for_abi ()
{
    local ABI=$1
    local BUILDDIR="$2"
    local LIBSTDCXX="$3

and

case $LIBSTDCXX in
        gnu-*)
            LIBSTDCXX_LDLIBS="-lgnustl_shared"
 
        llvm*)
            LIBSTDCXX_LDLIBS="-lc++_shared"

You can verify that the prebuilt binaries (eg libboost_chrono.so) link to libc++_shared.so :

Boost-for-Android/build/boost/1.67.0/libs/llvm/armeabi-v7a> readelf -d libboost_chrono.so | grep 'NEEDED' 
 0x00000001 (NEEDED)                     Shared library: [libboost_system.so]
 0x00000001 (NEEDED)                     Shared library: [libc++_shared.so]
 0x00000001 (NEEDED)                     Shared library: [libstdc++.so]
 0x00000001 (NEEDED)                     Shared library: [libm.so]
 0x00000001 (NEEDED)                     Shared library: [libdl.so]
 0x00000001 (NEEDED)                     Shared library: [libc.so]

Note that it also links to libstdc++.so which is the minimalistic android system stl.
See Android C++ Library Support.
Im not sure if this is an issue, and it seems to happen implicitly as has been pointed out by others
eg android/ndk#105.

Did you try the test app ? It links to the prebuilt binaries and runs just fine. Im not sure how your app is configured differently. Its always safer to build all required libraries yourself, but if you your app also uses the llvm/clang toolchain and links their standard library (libc++_shared.so), then its pretty unlikely (though not impossible.. maybe if your ndk version and therefore std libs is not identical to the one I used - 17b?) that things dont work.

Did you modify the doIt.sh script to create the build that worked for you? What does your version of doIt.sh look like?

Thank you for the thorough explanation. I did not use your script at all, I simply grabbed the prebuilt binaries. When I did finally build it from source, I did so using https://github.com/moritz-wundke/Boost-for-Android on a Ubuntu machine with a few modifications to the repository.