gcc(Mingw-W64)编译windows程序,提示undefined reference to `__imp_GetStockObject' 的解决方法:加上-mwindows,问题解决。

#include <windows.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow)
{
WNDCLASSEX wndclass;
static LPCTSTR szAppName = TEXT("HelloWin");
HWND hWnd;
MSG msg;
wndclass.cbSize = sizeof(WNDCLASSEX);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL

本文介绍使用GCC(Mingw-W64)编译Windows程序时遇到的undefined reference to `__imp_GetStockObject'错误,并提供了解决方案。通过在编译命令中加入-mwindows选项,可以成功解决该问题。
最低0.47元/天 解锁文章
2929





