简体   繁体   English

Android JNI x264作为库提供了重定位R_ARM_MOVW_ABS_NC; 用-fPIC重新编译

[英]Android JNI x264 as a library give relocation R_ARM_MOVW_ABS_NC; recompile with -fPIC

I'm trying to build x264 library to use it in a shared library that I load using jni on android. 我正在尝试建立x264库,以在我在Android上使用jni加载的共享库中使用它。 I'm able to build everything as an executable without any error but when I build as a shared library I get errors with dynamic relocation of R_ARM_MOVW_ABS_NC: 我能够将所有内容构建为可执行文件而没有任何错误,但是当我构建为共享库时,由于动态重定位R_ARM_MOVW_ABS_NC而出现错误:

[armeabi-v7a] SharedLibrary  : libx264.so
/home/martin/bin/android-ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: /home/martin/Documents/Sources/ScreenSharingServer/app/src/main/obj/local/armeabi-v7a/objs/x264/common/arm/pixel-a.o: requires unsupported dynamic reloc R_ARM_MOVW_ABS_NC; recompile with -fPIC
/home/martin/bin/android-ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: /home/martin/Documents/Sources/ScreenSharingServer/app/src/main/obj/local/armeabi-v7a/objs/x264/common/arm/mc-a.o: requires unsupported dynamic reloc R_ARM_MOVW_ABS_NC; recompile with -fPIC
/home/martin/bin/android-ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: /home/martin/Documents/Sources/ScreenSharingServer/app/src/main/obj/local/armeabi-v7a/objs/x264/common/arm/dct-a.o: requires unsupported dynamic reloc R_ARM_MOVW_ABS_NC; recompile with -fPIC
/home/martin/bin/android-ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: /home/martin/Documents/Sources/ScreenSharingServer/app/src/main/obj/local/armeabi-v7a/objs/x264/common/arm/quant-a.o: requires unsupported dynamic reloc R_ARM_MOVW_ABS_NC; recompile with -fPIC
/home/martin/bin/android-ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: /home/martin/Documents/Sources/ScreenSharingServer/app/src/main/obj/local/armeabi-v7a/objs/x264/common/arm/predict-a.o: requires unsupported dynamic reloc R_ARM_MOVW_ABS_NC; recompile with -fPIC
collect2: error: ld returned 1 exit status
make: *** [/home/martin/Documents/Sources/ScreenSharingServer/app/src/main/obj/local/armeabi-v7a/libx264.so] Error 1

Here is my android.mk: 这是我的android.mk:

LOCAL_PATH := $(my-dir)

include $(CLEAR_VARS)

APP_ABI := armeabi armeabi-v7a
TARGET_ARCH_ABI := armeabi-v7a
LOCAL_ARM_NEON := true
ARCH_ARM_HAVE_NEON := true

AM_CFLAGS := -march=armv7-a -mfpu=neon
AM_CCASFLAGS := -march=armv7-a -mfpu=neon

LOCAL_SRC_FILES:= common/mc.c common/predict.c common/pixel.c common/macroblock.c \
       common/frame.c common/dct.c common/cpu.c common/cabac.c \
       common/common.c common/osdep.c common/rectangle.c \
       common/set.c common/quant.c common/deblock.c common/vlc.c \
       common/mvpred.c common/bitstream.c \
       encoder/analyse.c encoder/me.c encoder/ratecontrol.c \
       encoder/set.c encoder/macroblock.c encoder/cabac.c \
       encoder/cavlc.c encoder/encoder.c encoder/lookahead.c \
       common/threadpool.c \
       common/arm/mc-c.c common/arm/predict-c.c \
       x264.c \
       common/arm/cpu-a.S common/arm/pixel-a.S common/arm/mc-a.S \
       common/arm/dct-a.S common/arm/quant-a.S common/arm/deblock-a.S \
       common/arm/predict-a.S

LOCAL_SHARED_LIBRARIES := libcutils
LOCAL_STATIC_LIBRARIES := swscale

LOCAL_C_INCLUDES := $(LOCAL_PATH) $(LOCAL_PATH)/..
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) $(LOCAL_PATH)/..

LOCAL_CFLAGS := -fPIC -O3 -ffast-math -fstrict-aliasing -DANDROID -std=c99
LOCAL_CPPFLAGS := -fPIC
LOCAL_LDFLAGS := -lm
LOCAL_MODULE := x264

include $(BUILD_SHARED_LIBRARY)

When I build with V=1 I see -fPIC option in every compilation line... 当我使用V = 1进行编译时,我在每个编译行中都看到-fPIC选项...

I wonder if anybody can help me understand what I do wrong. 我想知道是否有人可以帮助我了解我做错了什么。

Thanks for your time! 谢谢你的时间!

Martin 马丁

All the problematic object files (eg quant-ao) come from assembly files (quant-aS) Looking at the assembly sources from http://git.videolan.org/?p=x264.git;a=tree;f=common/arm;h=64e8990fc2043750599c45593f1bc7698d94048a;hb=refs/heads/master , it looks like you should have the PIC macro defined in your config.h 所有有问题的目标文件(例如,quantum-ao)都来自程序集文件(quant-aS)。从http://git.videolan.org/?p=x264.git;a=tree;f=common查看程序集源代码/ arm; h = 64e8990fc2043750599c45593f1bc7698d94048a; hb = refs / heads / master ,看起来您应该在config.h中定义了PIC宏

Normally, this is done by the x264 script if you use "./configure --enable-pic ..." I'm guessing you're using a custom config.h, if so add a '#define PIC 1' in it, or simply add -DPIC=1 to your LOCAL_CFLAGS 通常,如果您使用“ ./configure --enable-pic ...”,这是通过x264脚本完成的,我猜测您使用的是自定义config.h,如果这样,请在其中添加“ #define PIC 1”它,或直接将-DPIC = 1添加到您的LOCAL_CFLAGS

hope this helps. 希望这可以帮助。

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

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