简体   繁体   English

ndk-build .so不兼容的目标(预建的共享库)

[英]ndk-build .so incompatible target (prebuilt shared library)

 LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE    := slabhidtouart
LOCAL_SRC_FILES := libslabhidtouart.so
include $(PREBUILT_SHARED_LIBRARY) 

include $(CLEAR_VARS)

LOCAL_MODULE    := TestJNI
### Add all source file names to be included in lib separated by a whitespace
LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_SRC_FILES := TestJNI.cpp 
LOCAL_SHARED_LIBRARIES := slabhidtouart
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/jni
include $(BUILD_SHARED_LIBRARY)

compiling with ndk build giving error 用ndk构建编译给出错误

testjni1//obj/local/armebai/libslabhidtouart.so: incompatible target

can anyone tell me where i am going wrong 谁能告诉我哪里出错了

Edit: using readelf -di got this 编辑: using readelf -di got this

Dynamic section at offset 0x1fd90 contains 28 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libusb-1.0.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libstdc++.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libgcc_s.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x000000000000000e (SONAME)             Library soname: [libslabhidtouart.so.1]

some libraries are marked as needed what that means. 一些图书馆根据需要标记了这意味着什么。

actually i am new to this kind of projects so i was confused with what i need and what i have to do next. 实际上我是这类项目的新手,所以我对我需要的东西以及接下来要做的事感到困惑。 now i got some things like i was using a library which is built for another cpu(x86_64) and i need library for ARM, thanks to you guys, you make me clear 现在我得到了一些东西,比如我正在使用为另一个cpu(x86_64)构建的库,我需要ARM库,感谢你们,你们让我说清楚

This reference: 这个参考:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE    := slabhidtouart
LOCAL_SRC_FILES := libslabhidtouart.so
include $(PREBUILT_SHARED_LIBRARY) 

means that you want to use libslabhidtouart.so when compiling your module. 意味着您要在编译模块时使用libslabhidtouart.so But .so files are binaries that are compatible only with one specific cpu-architecture/OS. 但.so文件是仅与一个特定的cpu架构/操作系统兼容的二进制文件。

The error you're getting means that ndk-build is trying to use your .so file while compiling your module for an incompatible target. 您获得的错误意味着ndk-build在为不兼容的目标编译模块时尝试使用.so文件。

Android supports several cpu architectures (armeabi, armeabi-v7a, arm64-v8a, x86, x86_64, mips, mips64). Android支持多种cpu架构(armeabi,armeabi-v7a,arm64-v8a,x86,x86_64,mips,mips64)。 You can choose which one you want to support using the APP_ABI variable from Application.mk . 您可以使用Application.mk中APP_ABI变量选择要支持的那个 If you set it to all , ndk-build will try to use this .so file you're referencing for each of these architectures, but this cannot work. 如果将其设置为all ,ndk-build将尝试使用您为每个体系结构引用的.so文件,但这不起作用。

Your .so file must have been compiled for Android platforms, and you need to have a different version of it for each architecture you're supporting. 您的.so文件必须已针对Android平台进行编译,并且您需要为您支持的每个体系结构提供不同版本的.so文件。 You can give a dynamic reference to the right .so file, such as LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libslabhidtouart.so so it looks for your .so file under armeabi-v7a folder when compiling for armeabi-v7a, under x86 for x86, etc. 您可以给右侧.so文件提供动态引用,例如LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libslabhidtouart.so以便在编译armeabi-v7a时查找armeabi-v7a文件夹下的.so文件,x86下为x86等

Of course you need to provide these .so files. 当然,您需要提供这些.so文件。 If you can't get .so files for all the supported architectures, you'll have to restrict your APP_ABI to the architectures of the .so file you have. 如果您无法获得所有支持的体系结构的.so文件,则必须将APP_ABI限制为您APP_ABI的.so文件的体系结构。 You can determine the architecture your .so file has been compiled for using readelf. 您可以使用readelf确定已编译的.so文件的体系结构。

edit: your latest comment precise that your .so file has been compiled for x86, but I also suspect it's for standard Linux, not Android. 编辑:你的最新评论确切地说你的.so文件是为x86编译的,但我也怀疑它是针对标准的Linux,而不是Android。 You can use readelf -d to check your lib dependencies. 您可以使用readelf -d来检查lib依赖项。

prebuilt libraries should be built with corresponding NDK standlone toolchain, somethings like "arm-linux-androideabi-4.9","x86-4.9"... 预建库应该用相应的NDK standlone工具链构建,比如“arm-linux-androideabi-4.9”,“x86-4.9”...

you can find them in the folder /toochains/ 你可以在文件夹/ toochains /中找到它们

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE    := slabhidtouart
LOCAL_SRC_FILES := libslabhidtouart.so
include $(PREBUILT_SHARED_LIBRARY) 

compiling with ndk build giving error: 用ndk构建编译给出错误:

testjni1//obj/local/armebai/libslabhidtouart.so: incompatible target testjni1 // obj / local / armebai / libslabhidtouart.so:不兼容的目标

chmod a+x solve it

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM