为什么在Android NDK中将静态库与CMake链接时仍会出现未定义的参考错误? [英] Why am I still getting undefined reference errors linking a static library with CMake in Android NDK?

查看:115
本文介绍了为什么在Android NDK中将静态库与CMake链接时仍会出现未定义的参考错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在构建以下Android-NDK项目时,由于缺少标准库功能,我收到许多未定义的参考错误.我遵循了一些链接静态库的基本示例,并从头开始重新启动了此项目3次,但仍然找不到问题.我正在尝试使用通过-std=c++1z编译的lib_seal库. ( https://www.microsoft.com/zh-CN/research/project/simple-encrypted-arithmetic-library/).

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/).

我遇到的错误表明该库已正确链接,但根据许多在线参考资料,它找不到-lstdc++(一个示例,建议在此处:"-std=c++11""-lstdc++"等.我还尝试了添加arguments "-DANDROID_STL=c++_shared".

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:

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:

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:

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());
}

错误消息:

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.

仅需注意几点:我需要使用-std=c++1z来使用SEAL库(或-std=gnu++1z),并且在gradle文件的末尾,我只允许使用x86_64体系结构,因为我不想担心关于交叉编译任何东西,直到我开始工作.

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.

推荐答案

看来libseal是使用GNU的libstdc ++(较老的NDK而言,是gnustl)由较旧的NDK构建的. GNU的libstdc ++不再包含在NDK r18中.您需要使用libc ++重建libseal或降级NDK.

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.

这篇关于为什么在Android NDK中将静态库与CMake链接时仍会出现未定义的参考错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆