gpt4 book ai didi

armeabi-v7a : "PLT offset too large, try linking with --long-plt" 的 Android NDK 链接器失败

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:30:40 49 4
gpt4 key购买 nike

尝试构建已签名的 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

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

externalNativeBuild {
cmake {
...
arguments '-DANDROID_STL=c++_static', '-Wl,--long-plt'
cppFlags "-frtti -fexceptions", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_STL=c++_shared"
}
}

但似乎并没有改变什么。

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

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

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

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

最佳答案

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

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

externalNativeBuild {
cmake {
...
arguments '-DANDROID_STL=c++_static'
cppFlags "-frtti -fexceptions", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_STL=c++_shared", "-Wl,--long-plt"
}
}

如果有什么变化,请告诉我?

关于armeabi-v7a : "PLT offset too large, try linking with --long-plt" 的 Android NDK 链接器失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53016698/

49 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com