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

时间:2014-06-24 09:41:15

标签: android compilation android-ndk java-native-interface x264

我正在尝试构建x264库,以便在我使用jni在android上加载的共享库中使用它。我能够将所有内容构建为可执行文件而不会出现任何错误,但是当我构建为共享库时,我会因动态重定位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

这是我的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)

当我用V = 1构建时,我在每个编译行中看到-fPIC选项...

我想知道是否有人可以帮我理解我做错了什么。

谢谢你的时间!

马丁

1 个答案:

答案 0 :(得分:1)

所有有问题的对象文件(例如quant-a.o)来自汇编文件(quant-a.S) 查看来自http://git.videolan.org/?p=x264.git;a=tree;f=common/arm;h=64e8990fc2043750599c45593f1bc7698d94048a;hb=refs/heads/master的汇编源代码,看起来您应该在config.h中定义PIC宏

通常情况下,如果您使用“./configure --enable-pic ...”,则由x264脚本完成。 我猜你正在使用自定义config.h,如果这样,在其中添加'#define PIC 1',或者只是将-DPIC = 1添加到你的LOCAL_CFLAGS

希望这会有所帮助。