未定义引用错误,不能创建共享库 [英] Undefined reference error, can not create shared library

查看:531
本文介绍了未定义引用错误,不能创建共享库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试了很多方法来解决问题,但没有运气。这里是我的Andr​​oid.mk:

Tried so many ways to solve problem but no luck. Here is my 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文件夹下有到.CPP关于makefile文件相关的所有头.HPP文件,也有所有静态.A库和包括文件夹中涉及到的静态库中的所有头文件。我使用ndk9c版本。
下面是错误日志的一部分:

In jni folder there are all header .hpp files related to .cpp files on makefile, also there are all static .a libraries and "include" folder where all header files related to static libraries are. I'm using ndk9c version. Here is part of error log:

[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/tool​​chains/llvm-3.3/$p$pbuilt/linux-x86/bin/clang++轮候册,-soname,libmedia.so -shared --sysroot = /家庭/ PRO / Android的NDK-R9C /平台/ Android的9 /弓臂./obj/local/armeabi/objs/media/P_Decoding.o ./obj/local/armeabi/objs/media/P_Encoding.o JNI / libavformat流.A JNI / libav codec.a JNI / libavutil.a JNI / libswscale.a -lgcc ./obj/local/armeabi/libgnustl_shared.so -gcc工具链的/ home / PRO / Android的NDK-R9C /工具链/arm-linux-androideabi-4.8/$p$pbuilt/linux-x86 -no-canonical- prefixes -target的ARMv5TE-NONE-Linux的androideabi轮候册, - 没有不确定-Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,现在-L /家庭/ PRO / Android的NDK-R9C /平台/ Android的9 /弓臂/ 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

/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,now -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'

任何帮助,请。在此先感谢

Any help please. Thanks in advance

推荐答案

请确保您已经添加了的externC围绕包括libav $ C $的块CC和swscale头,如像这样的:

Make sure you have added the extern "C" block around the include of the libavcodec and swscale headers, e.g. like this:

extern "C" {
#include <libavcodec/avcodec.h>
#include <libswscale/swscale.h>
}

请参阅https://libav.org/faq.html#I_0027m-using-Libav-from-within-my-C_002b_002b-application-but-the-linker-complains-about-missing-symbols-which-seem-to-be-available_002e的文档,对此做出解释。

See https://libav.org/faq.html#I_0027m-using-Libav-from-within-my-C_002b_002b-application-but-the-linker-complains-about-missing-symbols-which-seem-to-be-available_002e for documentation that explains this.

编辑:另外,你确定了prebuilt libav codec.a是相同的体系结构(armeabi-V7A)为你建立?如果您正在为多种架构(armeabi-V7A,X86等)的共享库,你需要有prebuilt库的多个版本的对应也。

Also, are you sure that the prebuilt libavcodec.a is for the same architecture (armeabi-v7a) as you're building? If you are building your shared library for multiple architectures (armeabi-v7a, x86, etc) you need to have multiple corresponding versions of the prebuilt libraries as well.

这篇关于未定义引用错误,不能创建共享库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆