同じ名前のC++関数でac関数を呼び出す方法は? cヘッダーを使用するために「extern "c"」を呼び出し、c関数を使用するために「::」操作を呼び出しますが、リンクエラーが発生します。
私のコード:
extern "C" {
#include <libavcodec/avcodec.h>
}
...
class DllAvCodec
{
public:
...
virtual void av_free_packet(AVPacket *pkt) { ::av_free_packet(pkt); }
...
}
エラー:
D:/player/jni/lib/DllAvCodec.h:143: error: undefined reference to 'av_free_packet(AVPacket*)'
コード「::av_free_packet(pkt)」が undefined を呼び出すのはなぜですか?
私の Android.mk は:
LOCAL_PATH := $(call my-dir)
DEFINES += \
-DTARGET_POSIX \
-DTARGET_LINUX \
-D_LINUX \
-DTARGET_ANDROID \
-D__STDC_CONSTANT_MACROS
######################################
#build ffmpeg prebuilt lib
######################################
include $(CLEAR_VARS)
LOCAL_MODULE := libavcodec
LOCAL_SRC_FILES := lib/lib/libavcodec.a
LOCAL_EXPORT_C_INCLUDES +=$(LOCAL_PATH)/lib/include
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libavfilter
LOCAL_SRC_FILES := lib/lib/libavfilter.a
LOCAL_EXPORT_C_INCLUDES +=$(LOCAL_PATH)/lib/include
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libavformat
LOCAL_SRC_FILES := lib/lib/libavformat.a
LOCAL_EXPORT_C_INCLUDES +=$(LOCAL_PATH)/lib/include
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libavutil
LOCAL_SRC_FILES := lib/lib/libavutil.a
LOCAL_EXPORT_C_INCLUDES +=$(LOCAL_PATH)/lib/include
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libpostproc
LOCAL_SRC_FILES := lib/lib/libpostproc.a
LOCAL_EXPORT_C_INCLUDES +=$(LOCAL_PATH)/lib/include
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libswresample
LOCAL_SRC_FILES := lib/lib/libswresample.a
LOCAL_EXPORT_C_INCLUDES +=$(LOCAL_PATH)/lib/include
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libswscale
LOCAL_SRC_FILES := lib/lib/libswscale.a
LOCAL_EXPORT_C_INCLUDES +=$(LOCAL_PATH)/lib/include
include $(PREBUILT_STATIC_LIBRARY)
######################################
#build lib
######################################
include $(CLEAR_VARS)
LOCAL_MODULE:= player
base := $(LOCAL_PATH)
LOCAL_SRC_FILES += ......
LOCAL_CPPFLAGS += -Wall -fexceptions $(DEFINES)
LOCAL_LDLIBS += -llog -lz
LOCAL_LDFLAGS += -L../jni/lib/lib -lavcodec -lavformat -lavutil -lavfilter -lpostproc -lswscale -lswresample
LOCAL_STATIC_LIBRARIES := libavcodec \
libavformat \
libavutil \
libavfilter \
libpostproc \
libswscale \
libswresample
include $(BUILD_SHARED_LIBRARY)