[英]Calling a C function from C++, “no matching function” error
I've defined the following header file (in C), left out the function implementation since thise aren't needed: 我已经定义了以下头文件(在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_*/
In C++, I defined my second header file: 在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
In, mediametadataretriever.cpp I defined the following function: 在,mediametadataretriever.cpp中我定义了以下函数:
int MediaMetadataRetriever::setDataSource(
const char *srcUrl)
{
// should call C function
AVFormatContext* pFormatCtx;
return setDataSource(&pFormatCtx, srcUrl);
}
When I try to compile this (C++) project in Eclipse I get a "No matching function call..." error related to: 当我尝试在Eclipse中编译这个(C ++)项目时,我得到一个“No matching function call ...”错误,该错误与:
return setDataSource(&pFormatCtx, srcUrl);
If I comment out the call, the code compiles fine: 如果我注释掉了这个电话,代码编译得很好:
int MediaMetadataRetriever::setDataSource(
const char *srcUrl)
{
return 0;
}
This appears to be a linking issue, does anyone know what I'm doing wrong? 这似乎是一个链接问题,有谁知道我做错了什么?
setDataSource
in that context is the name of the member function. 该上下文中的
setDataSource
是成员函数的名称。 To invoke the free function, try fully qualifying its name: 要调用自由函数,请尝试完全限定其名称:
return ::setDataSource(&pFormatCtx, srcUrl);
// ^^
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.