Sirop4ik
Sirop4ik

Reputation: 5243

How to solve link errors while MediaFoundation using?

I have a solution that is works, then I was needed to add a project that has implementation of MediaFoundation. So, in order to include it I added this project as existing one then in configuration in General section I provided path to .h files and then in Liker input added .lib

After this I tried to use it and write include in one of my files and then invoked a few methods from this project that was added.

When I tried to compile my project I got an errors :

9>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
9>co_AudioDecoder.lib(co_AudioDecoderMF.obj) : error LNK2019: unresolved external symbol MFStartup referenced in function "private: bool __cdecl co_AudioDecoderMF::InitAndStartCOMLib(void)" (?InitAndStartCOMLib@co_AudioDecoderMF@@AEAA_NXZ)
9>co_AudioDecoder.lib(co_AudioDecoderMF.obj) : error LNK2019: unresolved external symbol MFShutdown referenced in function "public: virtual void __cdecl co_AudioDecoderMF::Cleanup(void)" (?Cleanup@co_AudioDecoderMF@@UEAAXXZ)
9>co_AudioDecoder.lib(co_AudioDecoderMF.obj) : error LNK2019: unresolved external symbol MFCreateAttributes referenced in function "private: bool __cdecl co_AudioDecoderMF::CreateSourceReader(void)" (?CreateSourceReader@co_AudioDecoderMF@@AEAA_NXZ)
9>co_AudioDecoder.lib(co_AudioDecoderMF.obj) : error LNK2019: unresolved external symbol MFCreateMediaType referenced in function "private: bool __cdecl co_AudioDecoderMF::ConfigureAudioStream(enum co_AudioDecoder::SoundDataType,struct IMFSourceReader *,struct IMFMediaType * *)" (?ConfigureAudioStream@co_AudioDecoderMF@@AEAA_NW4SoundDataType@co_AudioDecoder@@PEAUIMFSourceReader@@PEAPEAUIMFMediaType@@@Z)
9>co_AudioDecoder.lib(co_AudioDecoderMF.obj) : error LNK2019: unresolved external symbol MFCreateMFByteStreamOnStream referenced in function "private: bool __cdecl co_AudioDecoderMF::CreateByteStream(unsigned char const *,__int64)" (?CreateByteStream@co_AudioDecoderMF@@AEAA_NPEBE_J@Z)
9>co_AudioDecoder.lib(co_AudioDecoderMF.obj) : error LNK2019: unresolved external symbol MFCreateSourceReaderFromByteStream referenced in function "private: bool __cdecl co_AudioDecoderMF::CreateSourceReader(void)" (?CreateSourceReader@co_AudioDecoderMF@@AEAA_NXZ)
9>co_AudioDecoder.lib(co_AudioDecoderMF.obj) : error LNK2001: unresolved external symbol MFAudioFormat_PCM
9>co_AudioDecoder.lib(co_AudioDecoderMF.obj) : error LNK2001: unresolved external symbol MF_MT_MAJOR_TYPE
9>co_AudioDecoder.lib(co_AudioDecoderMF.obj) : error LNK2001: unresolved external symbol MF_MT_SUBTYPE
9>co_AudioDecoder.lib(co_AudioDecoderMF.obj) : error LNK2001: unresolved external symbol MF_MT_AUDIO_NUM_CHANNELS
9>co_AudioDecoder.lib(co_AudioDecoderMF.obj) : error LNK2001: unresolved external symbol MF_MT_AUDIO_SAMPLES_PER_SECOND
9>co_AudioDecoder.lib(co_AudioDecoderMF.obj) : error LNK2001: unresolved external symbol MF_MT_AUDIO_BLOCK_ALIGNMENT
9>co_AudioDecoder.lib(co_AudioDecoderMF.obj) : error LNK2001: unresolved external symbol MF_MT_AUDIO_BITS_PER_SAMPLE
9>co_AudioDecoder.lib(co_AudioDecoderMF.obj) : error LNK2001: unresolved external symbol MFMediaType_Audio

First of all it is strange because I have already use this project in other solution and there weren't problems, but ok after a research I have found out that I need to add in configuration Linker -> input a few more .libs

Mf.lib
Mfplat.lib
mfuuid.lib

(inspire of I don't have these lines in my other solution where does it works) and after I added these lines a lot of error gone, but one left

9>co_AudioDecoder.lib(co_AudioDecoderMF.obj) : error LNK2019: unresolved external symbol MFCreateSourceReaderFromByteStream referenced in function "private: bool __cdecl co_AudioDecoderMF::CreateSourceReader(void)" (?CreateSourceReader@co_AudioDecoderMF@@AEAA_NXZ)

And I have not found nothing about how to solve it. I am a relatively new in c++ and it looks weird that in order to make MediaFoundation(big lib) work I need to spend a few hours in order to find out what to add in additional in order to make it works.

So, question is - what am I missing here?

Upvotes: 3

Views: 1507

Answers (2)

mkoenig334455
mkoenig334455

Reputation: 11

I use it that way:

#include "stdafx.h"
#include <mfapi.h>
#include <mfplay.h>
#include <mfreadwrite.h>
#include <vector>
#include <string>
#include <ks.h>
#include <ksproxy.h>
#include <vidcap.h>
#include "UVCExtensionApp.h"

/*
Libraries: https://learn.microsoft.com/en-us/windows/win32/medfound/media-foundation-headers-and-libraries
dxva2.lib
evr.lib
mf.lib
mfplat.lib
mfplay.lib
mfreadwrite.lib
mfuuid.lib
*/
#pragma comment(lib, "mf")
#pragma comment(lib, "mfplat")
#pragma comment(lib, "mfplay")
#pragma comment(lib, "mfreadwrite")
#pragma comment(lib, "mfuuid")

Upvotes: 1

mofo77
mofo77

Reputation: 1515

You need to include this :

#pragma comment(lib, "mfreadwrite")

Documentation usually helps :

MFCreateSourceReaderFromByteStream function

Upvotes: 2

Related Questions