moritz-wundke / Boost-for-Android

Android port of Boost C++ Libraries
MIT License
1.02k stars 483 forks source link

Can't compile using ICU #163

Open david-hoze opened 5 years ago

david-hoze commented 5 years ago

Hi, great work! I'm using your latest version, with NDK r19 and Boost 1.69.0. I'm on Ubuntu 18.04 and Android Studio 3.3.1. I'm trying to use Boost.Locale, but getting

Build command failed.
Error while executing process /home/david/Android/Sdk/cmake/3.6.4111459/bin/cmake with arguments {--build /home/david/dev/android/AppAndroidFilter/app/.externalNativeBuild/cmake/debug/x86_64 --target app}
[1/1] Linking CXX shared library ../../../../build/intermediates/cmake/debug/obj/x86_64/libapp.so
FAILED: : && /home/david/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++  --target=x86_64-none-linux-android21 --gcc-toolchain=/home/david/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64 -fPIC --sysroot /home/david/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/sysroot -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -Wa,--noexecstack -Wformat -Werror=format-security -stdlib=libc++ -std=c++17 -frtti -fexceptions -O0 -fno-limit-debug-info  -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libapp.so -o ../../../../build/intermediates/cmake/debug/obj/x86_64/libapp.so CMakeFiles/app.dir/src/main/cpp/app-router/app-router.cpp.o CMakeFiles/app.dir/src/main/cpp/app-router/tcp.cpp.o CMakeFiles/app.dir/src/main/cpp/app-mitm/MITM/AsyncProxyServer.cpp.o CMakeFiles/app.dir/src/main/cpp/app-mitm/MITM/ModerateTraffic.cpp.o CMakeFiles/app.dir/src/main/cpp/app-mitm/MITM/sslsplit/ssl.c.o CMakeFiles/app.dir/src/main/cpp/app-mitm/MITM/stdafx.cpp.o CMakeFiles/app.dir/src/main/cpp/app-mitm/AsyncProxyServerDelegate.cpp.o CMakeFiles/app.dir/src/main/cpp/app-mitm/app-mitm.cpp.o CMakeFiles/app.dir/src/main/cpp/app-mitm/thread-jni-env.cpp.o CMakeFiles/app.dir/src/main/cpp/app-mitm/java-methods.cpp.o CMakeFiles/app.dir/src/main/cpp/app-mitm/process-id.cpp.o CMakeFiles/app.dir/src/main/cpp/AsyncHarmony/AsyncHarmonyContext.cpp.o CMakeFiles/app.dir/src/main/cpp/AsyncHarmony/AsyncMessageClient.cpp.o CMakeFiles/app.dir/src/main/cpp/AsyncHarmony/AsyncMessageCommon.cpp.o CMakeFiles/app.dir/src/main/cpp/AsyncHarmony/CloudRules.cpp.o CMakeFiles/app.dir/src/main/cpp/AsyncHarmony/AsyncHarmonyHttpClient.cpp.o CMakeFiles/app.dir/src/main/cpp/AsyncHarmony/CatMessageClient.cpp.o CMakeFiles/app.dir/src/main/cpp/AsyncHarmony/Url.cpp.o CMakeFiles/app.dir/src/main/cpp/AsyncHarmony/OpSync.cpp.o CMakeFiles/app.dir/src/main/cpp/AsyncHarmony/StringUtilities.cpp.o CMakeFiles/app.dir/src/main/cpp/AsyncHarmony/CNStoredLog.cpp.o CMakeFiles/app.dir/src/main/cpp/AsyncHarmony/ThreadKeeper.cpp.o CMakeFiles/app.dir/src/main/cpp/AsyncHarmony/Locksmith.cpp.o CMakeFiles/app.dir/src/main/cpp/AsyncHarmony/FastStringsToFileFunnel.cpp.o CMakeFiles/app.dir/src/main/cpp/AsyncHarmony/NHideAndSeek.cpp.o CMakeFiles/app.dir/src/main/cpp/util.cpp.o CMakeFiles/app.dir/src/main/cpp/patch-table.cpp.o  /home/david/dev/android/AppAndroidFilter/Boost-for-Android/build/libs/x86_64/libboost_system-clang-mt-x64-1_69.a /home/david/dev/android/AppAndroidFilter/Boost-for-Android/build/libs/x86_64/libboost_thread-clang-mt-x64-1_69.a /home/david/dev/android/AppAndroidFilter/Boost-for-Android/build/libs/x86_64/libboost_filesystem-clang-mt-x64-1_69.a /home/david/dev/android/AppAndroidFilter/Boost-for-Android/icu/libs/x86_64/libicuuc.a /home/david/dev/android/AppAndroidFilter/Boost-for-Android/icu/libs/x86_64/libiconv.so /home/david/dev/android/AppAndroidFilter/Boost-for-Android/build/libs/x86_64/libboost_locale-clang-mt-x64-1_69.a /home/david/dev/android/AppAndroidFilter/Boost-for-Android/build/libs/x86_64/libboost_iostreams-clang-mt-x64-1_69.a /home/david/dev/android/AppAndroidFilter/build-openssl-android/openssl-lib/x86_64/libssl.a /home/david/dev/android/AppAndroidFilter/build-openssl-android/openssl-lib/x86_64/libcrypto.a /home/david/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/x86_64-linux-android/21/liblog.so -latomic -lm && :
libs/locale/src/encoding/uconv_codepage.ipp:139: error: undefined reference to 'icu_62::UnicodeString::~UnicodeString()'
libs/locale/src/encoding/uconv_codepage.ipp:139: error: undefined reference to 'icu_62::UnicodeString::~UnicodeString()'
libs/locale/src/encoding/../icu/uconv.hpp:95: error: undefined reference to 'ucnv_open_62'
libs/locale/src/encoding/../icu/uconv.hpp:112: error: undefined reference to 'UCNV_FROM_U_CALLBACK_STOP_62'
libs/locale/src/encoding/../icu/uconv.hpp:112: error: undefined reference to 'ucnv_setFromUCallBack_62'
libs/locale/src/encoding/../icu/uconv.hpp:116: error: undefined reference to 'UCNV_TO_U_CALLBACK_STOP_62'
libs/locale/src/encoding/../icu/uconv.hpp:116: error: undefined reference to 'ucnv_setToUCallBack_62'
libs/locale/src/encoding/../icu/uconv.hpp:104: error: undefined reference to 'UCNV_FROM_U_CALLBACK_SKIP_62'
libs/locale/src/encoding/../icu/uconv.hpp:104: error: undefined reference to 'ucnv_setFromUCallBack_62'
libs/locale/src/encoding/../icu/uconv.hpp:108: error: undefined reference to 'UCNV_TO_U_CALLBACK_SKIP_62'
libs/locale/src/encoding/../icu/uconv.hpp:108: error: undefined reference to 'ucnv_setToUCallBack_62'
libs/locale/src/encoding/../icu/uconv.hpp:98: error: undefined reference to 'ucnv_close_62'
libs/locale/src/encoding/../icu/uconv.hpp:120: error: undefined reference to 'ucnv_close_62'
libs/locale/src/encoding/../icu/uconv.hpp:125: error: undefined reference to 'ucnv_getMaxCharSize_62'
libs/locale/src/encoding/../icu/uconv.hpp:157: error: undefined reference to 'ucnv_close_62'
libs/locale/src/encoding/../icu/icu_util.hpp:19: error: undefined reference to 'u_errorName_62'
libs/locale/src/encoding/../icu/uconv.hpp:61: error: undefined reference to 'icu_62::UnicodeString::UnicodeString(char const*, int, UConverter*, UErrorCode&)'
libs/locale/src/encoding/../icu/uconv.hpp:64: error: undefined reference to 'icu_62::UnicodeString::~UnicodeString()'
libs/locale/src/encoding/../icu/uconv.hpp:134: error: undefined reference to 'ucnv_fromUChars_62'
libs/locale/src/encoding/uconv_codepage.ipp:54: error: undefined reference to 'icu_62::UnicodeString::~UnicodeString()'
libs/locale/src/encoding/../icu/uconv.hpp:286: error: undefined reference to 'u_strToUTF32_62'
libs/locale/src/encoding/../icu/uconv.hpp:246: error: undefined reference to 'icu_62::UnicodeString::UnicodeString(int, int, int)'
libs/locale/src/encoding/../icu/uconv.hpp:250: error: undefined reference to 'icu_62::UnicodeString::append(int)'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

I added these two libraries in my CMakeLists.txt file:

add_library( libiconv SHARED IMPORTED)

set_target_properties(libiconv PROPERTIES IMPORTED_LOCATION
        ${MY_ICONV_LIBS_DIR}/${ANDROID_ABI}/libiconv.so
        )
#-----------------------------------------
add_library( libicuuc STATIC IMPORTED)

set_target_properties(libicuuc PROPERTIES IMPORTED_LOCATION
        ${MY_ICONV_LIBS_DIR}/${ANDROID_ABI}/libicuuc.a
        )
#-----------------------------------------

I also used

android {
    ...
    sourceSets {
        main {
            // Android Studio doesn't package precompiled external (*.so) libs into apk, even if linked against via "add_library (... SHARED IMPORTED) in CMakeLists.txt
            // See eg https://stackoverflow.com/questions/24357687/how-to-include-so-library-in-android-studio/29234765
            // Hopefully this will be remedied in near future.
            // As a workaroun in the meantime, need to add them manually to jniLibs.srcDirs
            // Note: This causes ALL *.so files in ABI (eg "armeabi-v7a") subdir of this dir to get packaged into .apk - relative to "app" dir
            // If you want to just include those necessary (eh chrono,, system) copy/link them to a separate dir, and reference that dir here instead.
            jniLibs.srcDirs = [
                    // should contain any external libs which should be compiled in {armeabi-v7a,arm64-v8a,x86,x86_64,mips} subdirs
                    my_boost_dir_libs,
                    my_iconv_dir_lib
                    //, "src/main/JniLibs/boost" // could add additional dirs (with ABI subdirs) to be packaged into apk like this.
                    // Relative paths like this will be interpreted as relative to "app" dir
            ]
        }

    }
}

Is there something else I need to do in order to link these libraries?

pelya commented 5 years ago

You need to put libicuuc.a after libboost_locale in your linker command line, currently it's used before libboost_locale, and since it's a static library, any symbol that is not referenced from anywhere else is discarded by the linker. Move add_library(libicuuc) command in your CMakeLists.txt below the place where you are defining Boost libraries.

On Tue, Feb 19, 2019 at 2:37 PM David Hoze notifications@github.com wrote:

Hi, great work! I'm using your latest version, with NDK r19 and Boost 1.69.0. I'm on Ubuntu 18.04 and Android Studio 3.3.1. I'm trying to use Boost.Locale, but getting

Build command failed. Error while executing process /home/david/Android/Sdk/cmake/3.6.4111459/bin/cmake with arguments {--build /home/david/dev/android/AppAndroidFilter/app/.externalNativeBuild/cmake/debug/x86_64 --target app} [1/1] Linking CXX shared library ../../../../build/intermediates/cmake/debug/obj/x86_64/libapp.so FAILED: : && /home/david/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=x86_64-none-linux-android21 --gcc-toolchain=/home/david/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64 -fPIC --sysroot /home/david/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/sysroot -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -Wa,--noexecstack -Wformat -Werror=format-security -stdlib=libc++ -std=c++17 -frtti -fexceptions -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libapp.so -o ../../../../build/intermediates/cmake/debug/obj/x86_64/libapp.so CMakeFiles/app.dir/src/main/cpp/app-router/app-router.cpp.o CMakeFiles/app.dir/src/main/cpp/app-router/tcp.cpp.o CMakeFiles/app.dir/src/main/cpp/app-mitm/MITM/AsyncProxyServer.cpp.o CMakeFiles/app.dir/src/main/cpp/app-mitm/MITM/ModerateTraffic.cpp.o CMakeFiles/app.dir/src/main/cpp/app-mitm/MITM/sslsplit/ssl.c.o CMakeFiles/app.dir/src/main/cpp/app-mitm/MITM/stdafx.cpp.o CMakeFiles/app.dir/src/main/cpp/app-mitm/AsyncProxyServerDelegate.cpp.o CMakeFiles/app.dir/src/main/cpp/app-mitm/app-mitm.cpp.o CMakeFiles/app.dir/src/main/cpp/app-mitm/thread-jni-env.cpp.o CMakeFiles/app.dir/src/main/cpp/app-mitm/java-methods.cpp.o CMakeFiles/app.dir/src/main/cpp/app-mitm/process-id.cpp.o CMakeFiles/app.dir/src/main/cpp/AsyncHarmony/AsyncHarmonyContext.cpp.o CMakeFiles/app.dir/src/main/cpp/AsyncHarmony/AsyncMessageClient.cpp.o CMakeFiles/app.dir/src/main/cpp/AsyncHarmony/AsyncMessageCommon.cpp.o CMakeFiles/app.dir/src/main/cpp/AsyncHarmony/CloudRules.cpp.o CMakeFiles/app.dir/src/main/cpp/AsyncHarmony/AsyncHarmonyHttpClient.cpp.o CMakeFiles/app.dir/src/main/cpp/AsyncHarmony/CatMessageClient.cpp.o CMakeFiles/app.dir/src/main/cpp/AsyncHarmony/Url.cpp.o CMakeFiles/app.dir/src/main/cpp/AsyncHarmony/OpSync.cpp.o CMakeFiles/app.dir/src/main/cpp/AsyncHarmony/StringUtilities.cpp.o CMakeFiles/app.dir/src/main/cpp/AsyncHarmony/CNStoredLog.cpp.o CMakeFiles/app.dir/src/main/cpp/AsyncHarmony/ThreadKeeper.cpp.o CMakeFiles/app.dir/src/main/cpp/AsyncHarmony/Locksmith.cpp.o CMakeFiles/app.dir/src/main/cpp/AsyncHarmony/FastStringsToFileFunnel.cpp.o CMakeFiles/app.dir/src/main/cpp/AsyncHarmony/NHideAndSeek.cpp.o CMakeFiles/app.dir/src/main/cpp/util.cpp.o CMakeFiles/app.dir/src/main/cpp/patch-table.cpp.o /home/david/dev/android/AppAndroidFilter/Boost-for-Android/build/libs/x86_64/libboost_system-clang-mt-x64-1_69.a /home/david/dev/android/AppAndroidFilter/Boost-for-Android/build/libs/x86_64/libboost_thread-clang-mt-x64-1_69.a /home/david/dev/android/AppAndroidFilter/Boost-for-Android/build/libs/x86_64/libboost_filesystem-clang-mt-x64-1_69.a /home/david/dev/android/AppAndroidFilter/Boost-for-Android/icu/libs/x86_64/libicuuc.a /home/david/dev/android/AppAndroidFilter/Boost-for-Android/icu/libs/x86_64/libiconv.so /home/david/dev/android/AppAndroidFilter/Boost-for-Android/build/libs/x86_64/libboost_locale-clang-mt-x64-1_69.a /home/david/dev/android/AppAndroidFilter/Boost-for-Android/build/libs/x86_64/libboost_iostreams-clang-mt-x64-1_69.a /home/david/dev/android/AppAndroidFilter/build-openssl-android/openssl-lib/x86_64/libssl.a /home/david/dev/android/AppAndroidFilter/build-openssl-android/openssl-lib/x86_64/libcrypto.a /home/david/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/x86_64-linux-android/21/liblog.so -latomic -lm && : libs/locale/src/encoding/uconv_codepage.ipp:139: error: undefined reference to 'icu_62::UnicodeString::~UnicodeString()' libs/locale/src/encoding/uconv_codepage.ipp:139: error: undefined reference to 'icu_62::UnicodeString::~UnicodeString()' libs/locale/src/encoding/../icu/uconv.hpp:95: error: undefined reference to 'ucnv_open_62' libs/locale/src/encoding/../icu/uconv.hpp:112: error: undefined reference to 'UCNV_FROM_U_CALLBACK_STOP_62' libs/locale/src/encoding/../icu/uconv.hpp:112: error: undefined reference to 'ucnv_setFromUCallBack_62' libs/locale/src/encoding/../icu/uconv.hpp:116: error: undefined reference to 'UCNV_TO_U_CALLBACK_STOP_62' libs/locale/src/encoding/../icu/uconv.hpp:116: error: undefined reference to 'ucnv_setToUCallBack_62' libs/locale/src/encoding/../icu/uconv.hpp:104: error: undefined reference to 'UCNV_FROM_U_CALLBACK_SKIP_62' libs/locale/src/encoding/../icu/uconv.hpp:104: error: undefined reference to 'ucnv_setFromUCallBack_62' libs/locale/src/encoding/../icu/uconv.hpp:108: error: undefined reference to 'UCNV_TO_U_CALLBACK_SKIP_62' libs/locale/src/encoding/../icu/uconv.hpp:108: error: undefined reference to 'ucnv_setToUCallBack_62' libs/locale/src/encoding/../icu/uconv.hpp:98: error: undefined reference to 'ucnv_close_62' libs/locale/src/encoding/../icu/uconv.hpp:120: error: undefined reference to 'ucnv_close_62' libs/locale/src/encoding/../icu/uconv.hpp:125: error: undefined reference to 'ucnv_getMaxCharSize_62' libs/locale/src/encoding/../icu/uconv.hpp:157: error: undefined reference to 'ucnv_close_62' libs/locale/src/encoding/../icu/icu_util.hpp:19: error: undefined reference to 'u_errorName_62' libs/locale/src/encoding/../icu/uconv.hpp:61: error: undefined reference to 'icu_62::UnicodeString::UnicodeString(char const, int, UConverter, UErrorCode&)' libs/locale/src/encoding/../icu/uconv.hpp:64: error: undefined reference to 'icu_62::UnicodeString::~UnicodeString()' libs/locale/src/encoding/../icu/uconv.hpp:134: error: undefined reference to 'ucnv_fromUChars_62' libs/locale/src/encoding/uconv_codepage.ipp:54: error: undefined reference to 'icu_62::UnicodeString::~UnicodeString()' libs/locale/src/encoding/../icu/uconv.hpp:286: error: undefined reference to 'u_strToUTF32_62' libs/locale/src/encoding/../icu/uconv.hpp:246: error: undefined reference to 'icu_62::UnicodeString::UnicodeString(int, int, int)' libs/locale/src/encoding/../icu/uconv.hpp:250: error: undefined reference to 'icu_62::UnicodeString::append(int)' clang++: error: linker command failed with exit code 1 (use -v to see invocation) ninja: build stopped: subcommand failed.

I added these two libraries in my CMakeLists.txt file:

add_library( libiconv SHARED IMPORTED)

set_target_properties(libiconv PROPERTIES IMPORTED_LOCATION ${MY_ICONV_LIBS_DIR}/${ANDROID_ABI}/libiconv.so )

-----------------------------------------

add_library( libicuuc STATIC IMPORTED)

set_target_properties(libicuuc PROPERTIES IMPORTED_LOCATION ${MY_ICONV_LIBS_DIR}/${ANDROID_ABI}/libicuuc.a )

-----------------------------------------

I also used

android { ... sourceSets { main { // Android Studio doesn't package precompiled external (.so) libs into apk, even if linked against via "add_library (... SHARED IMPORTED) in CMakeLists.txt // See eg https://stackoverflow.com/questions/24357687/how-to-include-so-library-in-android-studio/29234765 // Hopefully this will be remedied in near future. // As a workaroun in the meantime, need to add them manually to jniLibs.srcDirs // Note: This causes ALL .so files in ABI (eg "armeabi-v7a") subdir of this dir to get packaged into .apk - relative to "app" dir // If you want to just include those necessary (eh chrono,, system) copy/link them to a separate dir, and reference that dir here instead. jniLibs.srcDirs = [ // should contain any external libs which should be compiled in {armeabi-v7a,arm64-v8a,x86,x86_64,mips} subdirs my_boost_dir_libs, my_iconv_dir_lib //, "src/main/JniLibs/boost" // could add additional dirs (with ABI subdirs) to be packaged into apk like this. // Relative paths like this will be interpreted as relative to "app" dir ] }

}

}

Is there something else I need to do in order to link these libraries?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/moritz-wundke/Boost-for-Android/issues/163, or mute the thread https://github.com/notifications/unsubscribe-auth/AAJewCb0twxPHLvFHBTbKzcMVP70O0Fxks5vO-_4gaJpZM4bC31g .

david-hoze commented 5 years ago

It's working, thanks!!