0

i found a code on github which takes a screenshot and saves it as a jpeg file. I copied and pasted it in notepad++, saved it, and compiled it with the following command:

g++ -mwindows screenshot.cpp -lgdiplus

and faced the following error:

C:\Users\USER\AppData\Local\Temp\ccTLI53G.o:screenshot.cpp:(.text+0x158): undefined reference to `CreateStreamOnHGlobal@12'
collect2.exe: error: ld returned 1 exit status

it seems to be this line which is causing the problem:

#include <stdio.h>
#include <windows.h>
#include <gdiplus.h>
#include <time.h>
//stuff....
HRESULT res = CreateStreamOnHGlobal(NULL, true, &istream);// this line (line 38)
//stuff....

Any help as to why the code is not working will be highly appreciated...

1 Answers1

2

According to this site:

CreateStreamOnHGlobal function (combaseapi.h) - Win32 apps | Microsoft Docs

The library that contains CreateStreamOnHGlobal function is Ole32.lib, so -lole32 should be added to the command line.

MikeCAT
  • 73,922
  • 11
  • 45
  • 70