如何在C ++函数中调用具有相同名称的c函数?

时间:2013-07-25 06:46:30

标签: android c++ dll linker ffmpeg

如何在C ++函数中调用具有相同名称的c函数? 调用'extern“c”'使用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)

0 个答案:

没有答案