执行 GDIplus C++ 代码时面临的"undefined reference to `CreateStreamOnHGlobal@12'"错误



我在github上找到了一个代码,它截取了一张截图并将其保存为jpeg文件。我把它复制并粘贴在记事本++中,保存它,并用以下命令编译它:

g++ -mwindows screenshot.cpp -lgdiplus

并面临以下错误:

C:UsersUSERAppDataLocalTempccTLI53G.o:screenshot.cpp:(.text+0x158): undefined reference to `CreateStreamOnHGlobal@12'
collect2.exe: error: ld returned 1 exit status

似乎是这条线造成了问题:

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

如有任何关于代码为何不起作用的帮助,我们将不胜感激

根据本网站:

CreateStreamOnHGlobal函数(combaseapi.h(-Win32应用程序|Microsoft Docs

包含CreateStreamOnHGlobal函数的库是Ole32.lib,因此应将-lole32添加到命令行中。

相关内容

最新更新