我已经定义了以下头文件(在 C 中),省略了函数实现,因为不需要这个:
#ifndef FFMPEG_MEDIAMETADATARETRIEVER_H_
#define FFMPEG_MEDIAMETADATARETRIEVER_H_
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavutil/dict.h>
int setDataSource(AVFormatContext** pFormatCtx, const char* path);
#endif /*FFMPEG_MEDIAMETADATARETRIEVER_H_*/
在 C++ 中,我定义了第二个头文件:
#ifndef MEDIAMETADATARETRIEVER_H
#define MEDIAMETADATARETRIEVER_H
using namespace std;
extern "C" {
#include "ffmpeg_mediametadataretriever.h"
}
class MediaMetadataRetriever
{
public:
MediaMetadataRetriever();
~MediaMetadataRetriever();
int setDataSource(const char* dataSourceUrl);
};
#endif // MEDIAMETADATARETRIEVER_H
在 mediametadataretriever.cpp 中,我定义了以下函数:
int MediaMetadataRetriever::setDataSource(
const char *srcUrl)
{
// should call C function
AVFormatContext* pFormatCtx;
return setDataSource(&pFormatCtx, srcUrl);
}
当我尝试在 Eclipse 中编译此 (C++) 项目时,我收到与以下内容相关的“没有匹配的函数调用...”错误:
return setDataSource(&pFormatCtx, srcUrl);
如果我注释掉调用,代码编译正常:
int MediaMetadataRetriever::setDataSource(
const char *srcUrl)
{
return 0;
}
这似乎是一个链接问题,有人知道我做错了什么吗?
最佳答案
setDataSource
在该上下文中是成员函数的名称。要调用自由函数,请尝试完全限定其名称:
return ::setDataSource(&pFormatCtx, srcUrl);
// ^^
关于c++ - 从 C++ 调用 C 函数, "no matching function"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15441156/