Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

#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:

#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:

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:

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?

like image 744
William Seemann Avatar asked Dec 07 '22 08:12

William Seemann


1 Answers

setDataSource in that context is the name of the member function. To invoke the free function, try fully qualifying its name:

return ::setDataSource(&pFormatCtx, srcUrl);
//     ^^
like image 160
Andy Prowl Avatar answered Dec 09 '22 13:12

Andy Prowl