Joh*_*n P 4 c++ reference undefined
我已经链接到 gdi32.lib。无奈之下,我还链接了两个不同版本的gdi32.lib以及gdiplus.lib,并包含了我能找到的所有gdi头文件,但无济于事。然而,这个问题是在额外链接之前开始的,所以我想我可以放心地假设我的问题不是库之间的冲突或任何类似的干扰。
包含/定义:
#define WINVER 0x0500
#define _WIN32_WINNT 0x0500
#include <iostream>
#include <process.h>
#include <windows.h>
#include <winuser.h>
#include <gdiplus.h>
#include "UVMap.h"
Run Code Online (Sandbox Code Playgroud)
相关代码:
case WM_PAINT:{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
HDC hdcMemory = CreateCompatibleDC(hdc);
BITMAP bmp = screen.getBitmap(hdcMemory);
BitBlt(hdc,0,0,w,h,hdcMemory,0,0,SRCCOPY);
EndPaint(hwnd,&ps);
DeleteDC(hdc);
}break;
Run Code Online (Sandbox Code Playgroud)
我在搜索此问题时发现的每个结果都声称您只需链接到 gdi32。以下是我添加的链接:
编辑:错误显示如下:
.../Testing.cpp:50: undefined reference to `CreateCompatibleDC@4'
.../Testing.cpp:52: undefined reference to `BitBlt@36'
Run Code Online (Sandbox Code Playgroud)
像那样?我在 Eclipse 中通过“项目”>“属性”>“路径变量”进行了链接。“链接资源”选项卡下没有任何条目,也无法编辑。
您需要链接到coredll.libCreateCompatibleDC。
您需要链接到Gdi32.lib forBitBlt .
作为参考,当您遇到涉及 Windows 函数的链接错误时,只需用 google 搜索该函数并转到该函数的 MSDN 文档(我已链接到这两个特定函数的两个页面),然后向下滚动到“要求”部分并确保您链接到指定的库。