-1

When building the following Android-NDK project I am getting dozens of undefined reference errors regarding missing standard library functions. I followed some basic examples of linking static libraries and restarted this project from scratch 3 times but I still can't find the issue. I am trying to use the lib_seal library that I compiled using -std=c++1z. (https://www.microsoft.com/en-us/research/project/simple-encrypted-arithmetic-library/).

The errors I am getting indicate the library is linked properly but according to many references online it cannot find -lstdc++ (One example recommending this is here: undefined reference to `std::ios_base::Init::Init()'). I have added this in my CMakeLists.txt under target_link_libraries, and I have tried editing the gradle file to include cppFlags = "-std=c++1z", "-std=c++11", "-lstdc++" etc. I have also tried adding arguments "-DANDROID_STL=c++_shared".

The following is from the closest I can seem to get this to compile and link:

CMakeLists.txt:

# Sets the minimum version of CMake required to build the native library.

cmake_minimum_required(VERSION 3.4.1)

add_library(lib_seal STATIC IMPORTED)

# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.

add_library( # Sets the name of the library.
        native-lib

        # Sets the library as a shared library.
        SHARED

        # Provides a relative path to your source file(s).
        src/main/cpp/native-lib.cpp)

# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.

find_library( # Sets the name of the path variable.
        log-lib

        # Specifies the name of the NDK library that
        # you want CMake to locate.
        log)

set_target_properties(lib_seal PROPERTIES IMPORTED_LOCATION
        ${CMAKE_SOURCE_DIR}/libs/seal/${ANDROID_ABI}/lib/libseal.a)

target_include_directories(native-lib PRIVATE
        ${CMAKE_SOURCE_DIR}/libs/seal/${ANDROID_ABI}/include)

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.

target_link_libraries(native-lib
        stdc++
        lib_seal
        ${log-lib})

build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.wyoumans.sealapp"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        externalNativeBuild {
            cmake {
                cppFlags "-std=c++1z"
            }
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    externalNativeBuild {
        cmake {
            path "CMakeLists.txt"
        }
    }
    splits {
        abi {
            enable true
            reset()
            include "x86_64"
            universalApk false
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

native-lib.cpp:

#include <jni.h>
#include <string>

#include "seal/seal.h"

extern "C" JNIEXPORT jstring JNICALL
Java_com_example_wyoumans_sealapp_MainActivity_stringFromJNI(
        JNIEnv *env,
        jobject /* this */) {
    seal::EncryptionParameters params;
    std::string hello = "Set params!";
    return env->NewStringUTF(hello.c_str());
}

Error message:

Build command failed.
Error while executing process /home/wyoumans/Android/Sdk/cmake/3.6.4111459/bin/cmake with arguments {--build /home/wyoumans/AndroidStudioProjects/SEALApp/app/.externalNativeBuild/cmake/debug/x86_64 --target native-lib}
[1/2] Building CXX object CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o
[2/2] Linking CXX shared library ../../../../build/intermediates/cmake/debug/obj/x86_64/libnative-lib.so
FAILED: : && /home/wyoumans/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++  --target=x86_64-none-linux-android21 --gcc-toolchain=/home/wyoumans/Android/Sdk/ndk-bundle/toolchains/x86_64-4.9/prebuilt/linux-x86_64 --sysroot=/home/wyoumans/Android/Sdk/ndk-bundle/sysroot -fPIC -isystem /home/wyoumans/Android/Sdk/ndk-bundle/sysroot/usr/include/x86_64-linux-android -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -std=c++1z -O0 -fno-limit-debug-info  -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -nostdlib++ --sysroot /home/wyoumans/Android/Sdk/ndk-bundle/platforms/android-21/arch-x86_64 -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -L/home/wyoumans/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/x86_64 -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libnative-lib.so -o ../../../../build/intermediates/cmake/debug/obj/x86_64/libnative-lib.so CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o  -lstdc++ ../../../../libs/seal/x86_64/lib/libseal.a /home/wyoumans/Android/Sdk/ndk-bundle/platforms/android-21/arch-x86_64/usr/lib64/liblog.so -latomic -lm "/home/wyoumans/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/x86_64/libc++_static.a" "/home/wyoumans/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/x86_64/libc++abi.a" && :
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::BigPoly::save(std::ostream&) const: error: undefined reference to 'std::ostream::write(char const*, long)'
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::BigPoly::save(std::ostream&) const: error: undefined reference to 'std::ostream::write(char const*, long)'
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::BigPoly::save(std::ostream&) const: error: undefined reference to 'std::ostream::write(char const*, long)'
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::BigPoly::alias(int, int, unsigned long*): error: undefined reference to 'std::invalid_argument::invalid_argument(char const*)'
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::BigPoly::alias(int, int, unsigned long*): error: undefined reference to 'std::invalid_argument::invalid_argument(char const*)'
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::BigPoly::alias(int, int, unsigned long*): error: undefined reference to 'std::invalid_argument::invalid_argument(char const*)'
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::BigPoly::alias(int, int, unsigned long*): error: undefined reference to 'std::invalid_argument::invalid_argument(char const*)'
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::BigPoly::operator=(seal::BigPoly const&): error: undefined reference to 'std::out_of_range::out_of_range(char const*)'
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::BigPoly::operator=(seal::BigPoly const&): error: undefined reference to 'std::out_of_range::out_of_range(char const*)'
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::BigPoly::load(std::istream&): error: undefined reference to 'std::istream::read(char*, long)'
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::BigPoly::load(std::istream&): error: undefined reference to 'std::istream::read(char*, long)'
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::BigPoly::load(std::istream&): error: undefined reference to 'std::istream::read(char*, long)'
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::BigPoly::load(std::istream&): error: undefined reference to 'std::istream::read(char*, long)'
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function std::vector<seal::BigUInt, std::allocator<seal::BigUInt> >::_M_default_append(unsigned long): error: undefined reference to 'std::__throw_length_error(char const*)'
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_assign(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&): error: undefined reference to 'std::__throw_length_error(char const*)'
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::util::poly_to_hex_string[abi:cxx11](unsigned long const*, int, int): error: undefined reference to 'std::ios_base::ios_base()'
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::util::poly_to_hex_string[abi:cxx11](unsigned long const*, int, int): error: undefined reference to 'vtable for std::basic_ios<char, std::char_traits<char> >'
/home/wyoumans/Android/Sdk/ndk-bundle/toolchains/x86_64-4.9/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: the vtable symbol may be undefined because the class is missing its key function
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::util::poly_to_hex_string[abi:cxx11](unsigned long const*, int, int): error: undefined reference to 'VTT for std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> >'
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::util::poly_to_hex_string[abi:cxx11](unsigned long const*, int, int): error: undefined reference to 'std::basic_ios<char, std::char_traits<char> >::init(std::basic_streambuf<char, std::char_traits<char> >*)'
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::util::poly_to_hex_string[abi:cxx11](unsigned long const*, int, int): error: undefined reference to 'vtable for std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> >'
/home/wyoumans/Android/Sdk/ndk-bundle/toolchains/x86_64-4.9/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: the vtable symbol may be undefined because the class is missing its key function
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::util::poly_to_hex_string[abi:cxx11](unsigned long const*, int, int): error: undefined reference to 'vtable for std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> >'
/home/wyoumans/Android/Sdk/ndk-bundle/toolchains/x86_64-4.9/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: the vtable symbol may be undefined because the class is missing its key function
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::util::poly_to_hex_string[abi:cxx11](unsigned long const*, int, int): error: undefined reference to 'vtable for std::basic_streambuf<char, std::char_traits<char> >'
/home/wyoumans/Android/Sdk/ndk-bundle/toolchains/x86_64-4.9/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: the vtable symbol may be undefined because the class is missing its key function
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::util::poly_to_hex_string[abi:cxx11](unsigned long const*, int, int): error: undefined reference to 'std::locale::locale()'
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::util::poly_to_hex_string[abi:cxx11](unsigned long const*, int, int): error: undefined reference to 'vtable for std::__cxx11::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >'
/home/wyoumans/Android/Sdk/ndk-bundle/toolchains/x86_64-4.9/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: the vtable symbol may be undefined because the class is missing its key function
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::util::poly_to_hex_string[abi:cxx11](unsigned long const*, int, int): error: undefined reference to 'std::basic_ios<char, std::char_traits<char> >::init(std::basic_streambuf<char, std::char_traits<char> >*)'
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::util::poly_to_hex_string[abi:cxx11](unsigned long const*, int, int): error: undefined reference to 'std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long)'
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::util::poly_to_hex_string[abi:cxx11](unsigned long const*, int, int): error: undefined reference to 'std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long)'
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::util::poly_to_hex_string[abi:cxx11](unsigned long const*, int, int): error: undefined reference to 'std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long)'
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::util::poly_to_hex_string[abi:cxx11](unsigned long const*, int, int): error: undefined reference to 'vtable for std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> >'
/home/wyoumans/Android/Sdk/ndk-bundle/toolchains/x86_64-4.9/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: the vtable symbol may be undefined because the class is missing its key function
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::util::poly_to_hex_string[abi:cxx11](unsigned long const*, int, int): error: undefined reference to 'vtable for std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> >'
/home/wyoumans/Android/Sdk/ndk-bundle/toolchains/x86_64-4.9/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: the vtable symbol may be undefined because the class is missing its key function
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::util::poly_to_hex_string[abi:cxx11](unsigned long const*, int, int): error: undefined reference to 'vtable for std::__cxx11::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >'
/home/wyoumans/Android/Sdk/ndk-bundle/toolchains/x86_64-4.9/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: the vtable symbol may be undefined because the class is missing its key function
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::util::poly_to_hex_string[abi:cxx11](unsigned long const*, int, int): error: undefined reference to 'vtable for std::basic_streambuf<char, std::char_traits<char> >'
/home/wyoumans/Android/Sdk/ndk-bundle/toolchains/x86_64-4.9/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: the vtable symbol may be undefined because the class is missing its key function
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::util::poly_to_hex_string[abi:cxx11](unsigned long const*, int, int): error: undefined reference to 'std::locale::~locale()'
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::util::poly_to_hex_string[abi:cxx11](unsigned long const*, int, int): error: undefined reference to 'VTT for std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> >'
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::util::poly_to_hex_string[abi:cxx11](unsigned long const*, int, int): error: undefined reference to 'VTT for std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> >'
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::util::poly_to_hex_string[abi:cxx11](unsigned long const*, int, int): error: undefined reference to 'vtable for std::basic_ios<char, std::char_traits<char> >'
/home/wyoumans/Android/Sdk/ndk-bundle/toolchains/x86_64-4.9/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: the vtable symbol may be undefined because the class is missing its key function
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::util::poly_to_hex_string[abi:cxx11](unsigned long const*, int, int): error: undefined reference to 'std::ios_base::~ios_base()'
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::util::poly_to_hex_string[abi:cxx11](unsigned long const*, int, int): error: undefined reference to 'std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long)'
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::util::poly_to_hex_string[abi:cxx11](unsigned long const*, int, int): error: undefined reference to 'std::ostream::operator<<(int)'
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::util::poly_to_hex_string[abi:cxx11](unsigned long const*, int, int): error: undefined reference to 'vtable for std::__cxx11::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >'
/home/wyoumans/Android/Sdk/ndk-bundle/toolchains/x86_64-4.9/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: the vtable symbol may be undefined because the class is missing its key function
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::util::poly_to_hex_string[abi:cxx11](unsigned long const*, int, int): error: undefined reference to 'vtable for std::basic_streambuf<char, std::char_traits<char> >'
/home/wyoumans/Android/Sdk/ndk-bundle/toolchains/x86_64-4.9/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: the vtable symbol may be undefined because the class is missing its key function
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::util::poly_to_hex_string[abi:cxx11](unsigned long const*, int, int): error: undefined reference to 'std::locale::~locale()'
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::util::poly_to_hex_string[abi:cxx11](unsigned long const*, int, int): error: undefined reference to 'vtable for std::basic_ios<char, std::char_traits<char> >'
/home/wyoumans/Android/Sdk/ndk-bundle/toolchains/x86_64-4.9/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: the vtable symbol may be undefined because the class is missing its key function
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::util::poly_to_hex_string[abi:cxx11](unsigned long const*, int, int): error: undefined reference to 'std::ios_base::~ios_base()'
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::util::poly_to_hex_string[abi:cxx11](unsigned long const*, int, int): error: undefined reference to 'std::__throw_logic_error(char const*)'
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::util::poly_to_hex_string[abi:cxx11](unsigned long const*, int, int): error: undefined reference to 'std::__throw_logic_error(char const*)'
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::util::poly_to_hex_string[abi:cxx11](unsigned long const*, int, int): error: undefined reference to 'std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> >::~basic_ostringstream()'
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::util::poly_to_hex_string[abi:cxx11](unsigned long const*, int, int): error: undefined reference to 'std::__throw_length_error(char const*)'
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function seal::util::poly_to_hex_string[abi:cxx11](unsigned long const*, int, int): error: undefined reference to 'std::__throw_length_error(char const*)'
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function _GLOBAL__sub_I_bigpoly.cpp: error: undefined reference to 'std::ios_base::Init::Init()'
../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o):bigpoly.cpp:function _GLOBAL__sub_I_bigpoly.cpp: error: undefined reference to 'std::ios_base::Init::~Init()'
../../../../libs/seal/x86_64/lib/libseal.a(biguint.cpp.o):biguint.cpp:function seal::BigUInt::save(std::ostream&) const: error: undefined reference to 'std::ostream::write(char const*, long)'
../../../../libs/seal/x86_64/lib/libseal.a(biguint.cpp.o):biguint.cpp:function _GLOBAL__sub_I_biguint.cpp: error: undefined reference to 'std::ios_base::Init::Init()'
../../../../libs/seal/x86_64/lib/libseal.a(biguint.cpp.o):biguint.cpp:function _GLOBAL__sub_I_biguint.cpp: error: undefined reference to 'std::ios_base::Init::~Init()'
../../../../libs/seal/x86_64/lib/libseal.a(encryptionparams.cpp.o):encryptionparams.cpp:function _GLOBAL__sub_I_encryptionparams.cpp: error: undefined reference to 'std::ios_base::Init::Init()'
../../../../libs/seal/x86_64/lib/libseal.a(encryptionparams.cpp.o):encryptionparams.cpp:function _GLOBAL__sub_I_encryptionparams.cpp: error: undefined reference to 'std::ios_base::Init::~Init()'
../../../../libs/seal/x86_64/lib/libseal.a(smallmodulus.cpp.o):smallmodulus.cpp:function _GLOBAL__sub_I_smallmodulus.cpp: error: undefined reference to 'std::ios_base::Init::Init()'
../../../../libs/seal/x86_64/lib/libseal.a(smallmodulus.cpp.o):smallmodulus.cpp:function _GLOBAL__sub_I_smallmodulus.cpp: error: undefined reference to 'std::ios_base::Init::~Init()'
../../../../libs/seal/x86_64/lib/libseal.a(globals.cpp.o):globals.cpp:function std::map<int, std::vector<seal::SmallModulus, std::allocator<seal::SmallModulus> >, std::less<int>, std::allocator<std::pair<int const, std::vector<seal::SmallModulus, std::allocator<seal::SmallModulus> > > > >::map(std::initializer_list<std::pair<int const, std::vector<seal::SmallModulus, std::allocator<seal::SmallModulus> > > >, std::less<int> const&, std::allocator<std::pair<int const, std::vector<seal::SmallModulus, std::allocator<seal::SmallModulus> > > > const&): error: undefined reference to 'std::_Rb_tree_insert_and_rebalance(bool, std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, std::_Rb_tree_node_base&)'
../../../../libs/seal/x86_64/lib/libseal.a(globals.cpp.o):globals.cpp:function std::map<int, std::vector<seal::SmallModulus, std::allocator<seal::SmallModulus> >, std::less<int>, std::allocator<std::pair<int const, std::vector<seal::SmallModulus, std::allocator<seal::SmallModulus> > > > >::map(std::initializer_list<std::pair<int const, std::vector<seal::SmallModulus, std::allocator<seal::SmallModulus> > > >, std::less<int> const&, std::allocator<std::pair<int const, std::vector<seal::SmallModulus, std::allocator<seal::SmallModulus> > > > const&): error: undefined reference to 'std::_Rb_tree_decrement(std::_Rb_tree_node_base*)'
../../../../libs/seal/x86_64/lib/libseal.a(mempool.cpp.o):mempool.cpp:function seal::util::MemoryPoolMT::alloc_uint64_count() const [clone .localalias.53]: error: undefined reference to 'std::__throw_system_error(int)'
../../../../libs/seal/x86_64/lib/libseal.a(mempool.cpp.o):mempool.cpp:function seal::util::MemoryPoolMT::~MemoryPoolMT(): error: undefined reference to 'std::__throw_system_error(int)'
../../../../libs/seal/x86_64/lib/libseal.a(mempool.cpp.o):mempool.cpp:function seal::util::MemoryPoolMT::get_for_uint64_count(long): error: undefined reference to 'std::__throw_system_error(int)'
../../../../libs/seal/x86_64/lib/libseal.a(mempool.cpp.o):mempool.cpp:function seal::util::MemoryPoolMT::pool_count() const: error: undefined reference to 'std::__throw_system_error(int)'
../../../../libs/seal/x86_64/lib/libseal.a(uintarith.cpp.o):uintarith.cpp:function seal::util::divide_uint_uint_inplace(unsigned long*, seal::util::Modulus const&, int, unsigned long*, seal::util::MemoryPool&): error: undefined reference to 'std::__throw_bad_function_call()'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

Just a couple notes: I need to use -std=c++1z to use the SEAL library (or -std=gnu++1z), and towards the end of the gradle file I am specifically allowing only x86_64 architecture since I don't want to worry about cross-compiling anything until I get this working.

wyoumans
  • 350
  • 1
  • 3
  • 10

1 Answers1

3

It looks like libseal was built with an older NDK using GNU's libstdc++ (gnustl in NDK parlance). GNU's libstdc++ is no longer included in NDK r18. You need to either rebuild libseal with libc++ or downgrade your NDK.

Dan Albert
  • 10,079
  • 2
  • 36
  • 79
  • Thank you! I decided to build libseal using the NDK toolchain for x86_64 rather than g++ (since this uses clang and your advice seems to be easier to accomplish there I think?). I no longer have the error but I have a new one: I'm getting a lot of messages saying `requires dynamic ... which may overflow at runtime; recompile with -fPIC` referencing libseal. I added -fPIC to CXXFLAGS, CFLAGS, even to the end of CC and CXX but I still get the errors. – wyoumans Oct 03 '18 at 23:00
  • Anyway I will accept this once I confirm this fixed the error and didn't hide it behind a new one! – wyoumans Oct 03 '18 at 23:02
  • That's odd, I thought `-fPIC` was always be used for CMake. Is there some handwritten assembly in one of these libraries? The assembly may need to be fixed the handle that. See https://stackoverflow.com/q/3544035/632035 for more information. – Dan Albert Oct 03 '18 at 23:24
  • I guess anything is possible. I will look into it some more, thanks for the help! – wyoumans Oct 03 '18 at 23:30
  • I asked a follow-up question on this if you're interested. Thanks again! https://stackoverflow.com/questions/52654999/why-am-i-getting-this-android-studio-error-recompile-with-fpic – wyoumans Oct 04 '18 at 20:55