简体   繁体   English

在ndk-build期间如何解决“通用ELF中的重定位”?

[英]How to resolve “Relocations in Generic ELF” during ndk-build?

I'm trying to build a static library using a standalone toolchain for a project that has its own build process, which I then wrap with a C++ library and expose to Android (compiled with ndk-build). 我正在尝试使用具有独立构建过程的项目的独立工具链构建静态库,然后将其包装为C ++库并公开给Android(与ndk-build一起编译)。 However, on the ndk-build step I receive the following error: 但是,在ndk-build步骤中,我收到以下错误:

➜  jni /Users/chrisfosterelli/Library/Android/sdk/ndk-bundle/ndk-build                    
[arm64-v8a] Compile++      : wrapper <= wrapper.cpp
In file included from /Users/chrisfosterelli/workspace/android/jni/wrapper.cpp:9:
In file included from ../prebuild/include/valhalla/meili/universal_cost.h:7:
In file included from ../prebuild/include/valhalla/sif/dynamiccost.h:4:
In file included from ../prebuild/include/valhalla/baldr/directededge.h:5:
../prebuild/include/valhalla/baldr/graphconstants.h:432:11: warning: 21 enumeration values not handled in switch: 'kRoad', 'kRamp', 'kTurnChannel'... [-Wswitch]
  switch (use) {
          ^
1 warning generated.
[arm64-v8a] SharedLibrary  : libwrapper.so
/Users/chrisfosterelli/Library/Android/sdk/ndk-bundle/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: /Users/chrisfosterelli/workspace/android/jni/../prebuild/libvalhalla_meili.a(libvalhalla_meili_la-map_matcher_factory.o): Relocations in generic ELF (EM: 62)
[...above message repeated many times...]
/Users/chrisfosterelli/workspace/android/jni/../prebuild/libvalhalla_meili.a: error adding symbols: File in wrong format
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [/Users/chrisfosterelli/workspace/android/obj/local/arm64-v8a/libwrapper.so] Error 1
➜  jni ls /Users/chrisfosterelli/Library/Android/sdk/ndk-bundle/

This error indicates, as far as I can tell, that I'm trying to mix and match binaries compiled for different architectures. 据我所知,此错误表明我正在尝试混合和匹配针对不同体系结构编译的二进制文件。 However, from what I can tell the library is the correct architecture: 但是,据我所知,库是正确的体系结构:

root@eacbdb1c0e46:/meili/meili2/newtest# ar x libvalhalla_meili.a 
root@eacbdb1c0e46:/meili/meili2/newtest# file libvalhalla_meili_la-map_matcher_factory.o 
libvalhalla_meili_la-map_matcher_factory.o: ELF 64-bit LSB relocatable, ARM aarch64, version 1 (SYSV), not stripped
root@eacbdb1c0e46:/meili/meili2/newtest#

FWIW, these are my current Application.mk , FWIW,这些是我当前的Application.mk

APP_STL := c++_static
APP_CPPFLAGS := -frtti -std=gnu++11 -D_GLIBCXX_USE_C99
APP_CPPFLAGS += -fexceptions
NDK_TOOLCHAIN_VERSION := clang
APP_LDFLAGS := -latomic
APP_PLATFORM := android-21
APP_ABI := arm64-v8a

and Android.mk , Android.mk

LOCAL_PATH := $(call my-dir)

# static library info
include $(CLEAR_VARS)
LOCAL_MODULE := libvalhalla_meili
LOCAL_SRC_FILES := ../prebuild/libvalhalla_meili.a
LOCAL_EXPORT_C_INCLUDES := ../prebuild/include
include $(PREBUILT_STATIC_LIBRARY)

# wrapper info
include $(CLEAR_VARS)
LOCAL_C_INCLUDES += ../prebuild/include
LOCAL_MODULE    := wrapper
LOCAL_SRC_FILES := wrapper.cpp
LOCAL_STATIC_LIBRARIES := libvalhalla_meili
include $(BUILD_SHARED_LIBRARY)

Any ideas how to resolve this? 任何想法如何解决这个问题? I've tried a number of things but all of them lead to more (more obscure) errors, so I'm hoping someone here can point me in the correct direction! 我已经尝试了很多方法,但是所有这些方法都会导致更多(更模糊)的错误,所以我希望这里的人可以为我指明正确的方向!

I discovered the problem, but I wish I had a more insightful answer. 我发现了问题,但希望我有一个更深刻的答案。 Apparently the build process had created two library files. 显然,构建过程已经创建了两个库文件。 The one that I inspected was, of course, ARM64. 我检查过的那个当然是ARM64。 However the one that I actually copied to the Android device was x86. 但是,我实际复制到Android设备的是x86。

So, the error message was correct and so was the library file, but there was more than one file involved. 因此,错误消息是正确的,库文件也是正确的,但是涉及多个文件。 If you're running into the same problem and pretty sure your library is ARM64, double check that's actually the same file that is being compiled into the ndk build! 如果您遇到相同的问题,并且可以确定您的库是ARM64,请仔细检查是否与正在ndk构建中编译的文件相同!

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

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