尝试了很多方法来解决问题,但没有运气。这是我的Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := avcodec
LOCAL_SRC_FILES :=libavcodec.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := avutil
LOCAL_SRC_FILES :=libavutil.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := swscale
LOCAL_SRC_FILES :=libswscale.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := avformat
LOCAL_SRC_FILES :=libavformat.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := avresample
LOCAL_SRC_FILES :=libavresample.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := swresample
LOCAL_SRC_FILES :=libswresample.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := x264
LOCAL_SRC_FILES :=libx264.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
#------------------------------------------
LOCAL_C_INCLUDES := $(LOCAL_PATH)\
$(LOCAL_PATH)/include
LOCAL_MODULE := media
LOCAL_SRC_FILES := \
P_Decoding.cpp \
P_Encoding.cpp \
wrapper_for_ffmpeg.cpp
LOCAL_CPPFLAGS := -std=c++11 -pthread -frtti -fexceptions
LOCAL_ARM_MODE := arm
LOCAL_STATIC_LIBRARIES := avcodec avutil swscale avformat avresample swresample x264
LOCAL_LDLIBS := -llog -ljnigraphics -landroid -lz -lEGL
LOCAL_CPP_FEATURES := rtti exceptions
include $(BUILD_SHARED_LIBRARY)
在jni文件夹中,有与makefile上的.cpp文件相关的所有头文件.hpp文件,还有所有静态.a库和" include"所有与静态库相关的头文件所在的文件夹。我使用的是ndk9c版本。 以下是错误日志的一部分:
[armeabi-v7a] Compile++ thumb: media <= P_Decoding.cpp
[armeabi-v7a] Compile++ thumb: media <= P_Encoding.cpp
[armeabi-v7a] Compile++ thumb: media <= wrapper_for_ffmpeg.cpp
/home/pro/android-ndk-r9c/toolchains/llvm-3.3/prebuilt/linux-x86/bin/clang++ -Wl,-soname,libmedia.so -shared --sysroot = / home / pro / android -ndk-r9c / platforms / android-9 / arch-arm ./obj/local/armeabi/objs/media/P_Decoding.o ./obj/local/armeabi/objs/media/P_Encoding.o jni / libavformat.a jni /libavcodec.a jni / libavutil.a jni / libswscale.a -lgcc ./obj/local/armeabi/libgnustl_shared.so -gcc- toolchain / home / pro / android-ndk-r9c / toolchains / arm-linux-androideabi- 4.8 / prebuilt / linux-x86 -no-canonical-prefixes -target armv5te-none-linux-androideabi -Wl, - no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,现在-L / home / pro / android-ndk-r9c / platforms / android-9 / arch-arm / usr / lib -llog -ljnigraphics -lz -ldl -lgcc / home / pro / android-ndk-r9c / sources / cxx-stl / gnu-libstdc ++ / 4.8 / libs / armeabi / libsupc ++。a -lc -lm -o ./obj/local/armeabi/libmedia.so
jni/P_Decoding.cpp:10: error: undefined reference to 'avcodec_register_all'
jni/P_Decoding.cpp:17: error: undefined reference to 'avcodec_find_decoder'
jni/P_Decoding.cpp:14: error: undefined reference to 'avcodec_find_decoder_by_name'
jni/P_Decoding.cpp:24: error: undefined reference to 'avcodec_alloc_context3'
jni/P_Decoding.cpp:50: error: undefined reference to 'avcodec_open2'
jni/P_Decoding.cpp:56: error: undefined reference to 'avcodec_alloc_frame'
jni/P_Decoding.cpp:76: error: undefined reference to 'sws_getContext'
jni/P_Decoding.cpp:90: error: undefined reference to 'avcodec_decode_video2'
jni/P_Decoding.cpp:104: error: undefined reference to 'sws_scale'
jni/P_Decoding.cpp:118: error: undefined reference to 'avcodec_close'
请帮忙。提前致谢
答案 0 :(得分:3)
确保在libavcodec和swscale标头的包含周围添加了extern "C"
块,例如:像这样:
extern "C" {
#include <libavcodec/avcodec.h>
#include <libswscale/swscale.h>
}
答案 1 :(得分:0)
尝试ndk-build V=1
查看链接库的实际命令。你想最终得到
-lavformat -lavcodec -lavfilter -lavutil -lswscale
按此顺序(作为 here ),但我不确定avresample swresample x264
应该适合哪个地方。相应地重新排列 LOCAL_STATIC_LIBRARIES 。