armeabi-v7a的Android NDK链接器失败:"PLT偏移太大,尝试使用--long-plt链接"

Str*_*ers 5 android cmake android-ndk llvm-clang

在尝试构建已签名的APK时,它会以~100行重复失败:

Library/Android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: PLT offset too large, try linking with --long-plt
Run Code Online (Sandbox Code Playgroud)

我在参数中添加了--long-plt:

externalNativeBuild {
    cmake {
        ...
        arguments '-DANDROID_STL=c++_static', '-Wl,--long-plt'
        cppFlags "-frtti -fexceptions", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_STL=c++_shared"
    }
}
Run Code Online (Sandbox Code Playgroud)

但它似乎没有改变任何东西.

它适用于非签名(调试)apk生成并使用arm64-v8a.

我正在处理> 1GB的本机代码,所以我猜这是主要原因.

似乎几乎没有关于此的文档或搜索结果.

是否--long-plt需要在其他地方放?如果没有,是否有其他设置可以更改?或者将代码拆分成单独的库有帮助吗?

这是CMakeLists.txt供参考:

string(REPLACE "." "/" JAVA_GEN_SUBDIR ${JAVA_GEN_PACKAGE})
set(JAVA_GEN_DIR ${Project_SOURCE_DIR}/src/main/java/${JAVA_GEN_SUBDIR}/../../../../../generated)

# configure import libs
set(distribution_DIR ${PROJECT_SOURCE_DIR}/distribution)

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

cmake_minimum_required(VERSION 3.4.1)

# Note: One could use a 'GLOB' here, but newly added source files won't auto-regen build files
# After adding files, you'd need to 'touch' the CMakeLists.txt to re-gen

# SWIG required for build. Easy install is "brew install swig"
#Site: http://swig.org
find_package(SWIG REQUIRED)
include(${SWIG_USE_FILE})

# Remove old java files, in case we don't need to generate some of them anymore
#file(REMOVE_RECURSE ${JAVA_GEN_DIR})

# Ensure file recognized as C++ (otherwise, exported as C file)
set_property(SOURCE src/main/cpp/${LIBRARY_NAME}.i PROPERTY CPLUSPLUS ON)

# Setup SWIG flags and locations
set(CMAKE_SWIG_FLAGS -c++ -package ${JAVA_GEN_PACKAGE})
set(CMAKE_SWIG_OUTDIR ${JAVA_GEN_DIR})

# Export a wrapper file to Java, and link with the created C++ library
swig_add_module(${LIBRARY_NAME}_Wrapper java ${SWIG_I_FILE})
swig_link_libraries(${LIBRARY_NAME}_Wrapper ${LIBRARY_NAME})



# Include a location to the header files
include_directories(
    src/main/cpp
    ${NativeLibPath}
    ${LUAPATH}
    )

set(LUAPATH ${NativeLibPath}/lua)

    file(GLOB ALL_SOURCE_FILES
        "src/main/cpp/*.cpp"
        "${NativeLibPath}/*.cpp"
        "${LUAPATH}/*.c"
    )

# 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.
             ${LIBRARY_NAME}

             # Sets the library as a shared library.
             SHARED

             # Provides the list of files to compile.
             ${ALL_SOURCE_FILES} )

target_include_directories(${LIBRARY_NAME} PRIVATE)

# 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 )

# 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(
                       # Specifies the target library.
                       ${LIBRARY_NAME}
                       android
                       # Links the target library to the log library
                       # included in the NDK.
                       ${log-lib}
                     )
Run Code Online (Sandbox Code Playgroud)

Bsq*_* ℬℬ -1

我同意互联网上没有那么多文档,即使我们可以找到一些。

首先,尝试修改您的配置文件:

externalNativeBuild {
    cmake {
        ...
        arguments '-DANDROID_STL=c++_static'
        cppFlags "-frtti -fexceptions", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_STL=c++_shared", "-Wl,--long-plt"
    }
}
Run Code Online (Sandbox Code Playgroud)

让我知道,如果它改变了什么?