0

I was trying the example code on "How to Play Media Files with Media Foundation", and I tried to compile the code with the following makefile:

LDFLAGS = -LC:\\pathToWindowsSDK\\Lib\\10.0.22000.0\\um\\x64 -lMfplat -lMfuuid -lUser32 -lOle32 -lShlwapi -lMf
default: winmain.o player.o
    g++ winmain.o player.o -o a.exe

winmain.o: winmain.cpp player.h
    g++ winmain.cpp -c

player.o: player.cpp player.h
    g++ player.cpp $(LDFLAGS) -c

and I keep getting the following undefined references:

C:/Personal/Soft/mingw/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: player.o:player.cpp:(.rdata$.refptr.GUID_NULL[.refptr.GUID_NULL]+0x0): undefined reference to `GUID_NULL'
C:/Personal/Soft/mingw/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: player.o:player.cpp:(.rdata$.refptr.MR_VIDEO_RENDER_SERVICE[.refptr.MR_VIDEO_RENDER_SERVICE]+0x0): undefined reference to `MR_VIDEO_RENDER_SERVICE'
collect2.exe: error: ld returned 1 exit status
make: *** [Makefile:4: default] Error 1

Both are undefined errors of GUID, is there a library that I should link? I'm using MSYS g++ compiler, and Windows 11 SDK (10.0.22000). Thanks in advance!

Alvin
  • 5
  • 1
  • 2
  • Is [Undefined OLE references in external library even when linking with libole32](https://stackoverflow.com/questions/4611987/undefined-ole-references-in-external-library-even-when-linking-with-libole32) any help? – user4581301 May 11 '22 at 21:06
  • You need to `#include ` in one (but just one) of the compilation units that references these symbols, before including other headers. There's non-obvious interaction between `DEFINE_GUID` macro and the `initguid.h` header file. – Ben Voigt May 11 '22 at 21:39

1 Answers1

1

Try adding -luuid (Visual C++ projects created through Visual Studio link to uuid.lib by default).

SoronelHaetir
  • 14,104
  • 1
  • 12
  • 23
  • Thx so much! Follow up: It worked, but now I have undefined reference to `MFMediaType_Video', `MFMediaType_Audio', `MR_VIDEO_RENDER_SERVICE' and `MF_EVENT_TOPOLOGY_STATUS' pop up, I tried Mfuuid.lib, but it gave a bunch of multiple definition, is there a way to fix this as well? – Alvin May 12 '22 at 01:34
  • My official SDK has that in mfuuid.lib, but you have -lmfuuid, so not sure. I suggest you go to your mingw library directory and do a "grep -l MFMediaType_Video" – SoronelHaetir May 12 '22 at 02:03