gpt4 book ai didi

c++ - 未定义对 `TextOutW@20' 的引用,链接了 Gdi32.lib

转载 作者:行者123 更新时间:2023-11-30 03:19:39 24 4
gpt4 key购买 nike

This question询问有关 Windows 代码的“ undefined reference ”问题。显然,解决方案是链接 gdi32.lib

我链接了 gdi32.lib,但仍然出现错误:

14:26:24 **** Incremental Build of configuration Debug for project SomeWindows ****
Info: Internal Builder is used for build
g++ -O0 -g3 -Wall -c -fmessage-length=0 -o "src\\SomeWindows.o" "..\\src\\SomeWindows.cpp"
g++ -o SomeWindows.exe "src\\SomeWindows.o" "C:\\Program Files (x86)\\Windows Kits\\8.1\\Lib\\winv6.3\\um\\x64\\Gdi32.Lib"
src\SomeWindows.o: In function `Z7WndProcP6HWND__jjl@16':
C:\Users\Mxx\eclipse-workspace\SomeWindows\Debug/../src/SomeWindows.cpp:78: undefined reference to `TextOutW@20'
collect2.exe: Fehler: ld gab 1 als Ende-Status zurück

14:26:26 Build Failed. 1 errors, 0 warnings. (took 2s.139ms)

我正在尝试从 https://msdn.microsoft.com/en-us/library/bb384843.aspx 创建 Window 的示例,这是我的代码:

#define UNICODE
#include <windows.h>
#include <stdlib.h>
#include <string.h>
#include <tchar.h>

LRESULT CALLBACK WndProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam);


static TCHAR a[] = _T("My first C++ program");
static TCHAR b[] = _T("My first wstring");

int main () {

HINSTANCE hInstance = GetModuleHandle(0);

WNDCLASSEX wcex;

wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = a;
wcex.hIconSm = LoadIcon(wcex.hInstance, IDI_APPLICATION);

RegisterClassEx(&wcex);

HWND hWnd = CreateWindow(
a,
b,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
500, 100,
NULL,
NULL,
hInstance,
NULL
);

ShowWindow(hWnd,3);
UpdateWindow(hWnd);

MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int) msg.wParam;


}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){
PAINTSTRUCT ps;
HDC hdc;
TCHAR greeting[] = _T("I just write stuff here.");
switch (message)
{
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);

// Here your application is laid out.
// For this introduction, we just print out "Hello, Windows Desktop!"
// in the top left corner.
TextOut(hdc,
5, 5,
greeting, _tcslen(greeting));
// End application-specific layout section.

EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
break;
}
return 0;
}

错误的根源在某种程度上是显而易见的。 TextOut(...) 被定义为TextOutW(...),由wingdi.h 声明。但是我什至如何去找出实现应该在哪里呢? (根据对另一个问题的回答,我认为那是 gdi32.lib)我怎么才能找出问题所在? (错误消息中的 @20 是什么意思?)

我使用 Win 8.1(和 Win 8.1 SDK)、Eclipse CPP IDE 和 MingW。

最佳答案

gdi32.lib 和 Windows SDK 中的其他 *.lib 文件可与 Visual Studio 一起使用。

使用 lgdi32 而不是 gdi32.lib 将这些库与 gcc 一起使用。

您也可以改用 MinGW 库。对应的库文件有'lib'前缀和*.a扩展名:

gdi32.lib -> c:\MinGW\lib\libgdi32.a

另请注意,Windows 程序需要 -mwindows 编译器标志(如果您不想看到控制台窗口)

例子:

g++ -Wall file.cpp -mwindows c:\MinGW\lib\libgdi32.a -o app.exe    
//or
g++ -Wall file.cpp -mwindows -lgdi32 -o app.exe

关于c++ - 未定义对 `TextOutW@20' 的引用,链接了 Gdi32.lib,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53502082/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com