正在发布VS2013链接器错误(Win32API)..为什么?
Annoying VS2013 Linker Errors (Win32API)...why?
我开始了一个新的VS2013 Win32API项目,并添加了一些简单的绘图菜单项和协同响应代码:
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
HPEN hPen;
HPEN hOldPen;
HBRUSH hBrush;
HBRUSH hOldBrush;
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
// Need to randomize x,y coordinates
case ID_DRAW_CIRCLE:
/* draw a blue-bordered magenta-crosshatched circle */
hdc = GetDC(hWnd); /* get a DC for painting */
hPen = CreatePen(PS_SOLID, 3, RGB(0, 0, 255)); /* blue pen */
hBrush = CreateHatchBrush(HS_DIAGCROSS, RGB(255, 0, 255));
hOldPen = (HPEN)SelectObject(hdc, hPen); /* select into DC & */
hOldBrush = (HBRUSH)SelectObject(hdc, hBrush); /* save old object */
Ellipse(hdc, 100, 30, 180, 110); /* draw circle */
SelectObject(hdc, hOldBrush); /* displace brush */
DeleteObject(hBrush); /* delete brush */
SelectObject(hdc, hOldPen); /* same for pen */
DeleteObject(hPen);
ReleaseDC(hWnd, hdc); /* release the DC to end painting */
break;
case ID_DRAW_RECTANGLE:
/* draw a red-bordered, cyan-filled rectangle */
hdc = GetDC(hWnd); /* get a DC for painting */
hPen = CreatePen(PS_SOLID, 3, RGB(255, 0, 0)); /* red pen */
hBrush = CreateSolidBrush(RGB(0, 255, 255)); /* cyan brush */
hOldPen = (HPEN)SelectObject(hdc, hPen); /* select into DC & */
hOldBrush = (HBRUSH)SelectObject(hdc, hBrush); /* save old object */
Rectangle(hdc, 15, 15, 80, 60); /* draw rectangle */
SelectObject(hdc, hOldBrush); /* displace new brush */
DeleteObject(hBrush); /* delete it from DC */
SelectObject(hdc, hOldPen); /* same for pen */
DeleteObject(hPen);
ReleaseDC(hWnd, hdc); /* get rid of DC */
break;
case ID_DRAW_CLEARSCREEN:
hdc = GetDC(hWnd); //NULL gets whole screen
hBrush = CreateSolidBrush(RGB(255, 0, 0)); //create brush
SelectObject(hdc, hBrush); //select brush into DC
Rectangle(hdc, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)); //draw rectangle over whole screen
break;
case ID_DRAW_QUIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
没有什么疯狂的,但当我去编译这段代码时,我得到了大约30个未解决的符号错误:
Error 1 error LNK2019: unresolved external symbol __imp__LoadStringW@16 referenced in function _wWinMain@16 C:UsersJonathanDocumentsVisual Studio 2013ProjectsWin32DrawWin32DrawWin32Draw.obj Win32Draw
Error 2 error LNK2019: unresolved external symbol __imp__CreateHatchBrush@8 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) C:UsersJonathanDocumentsVisual Studio 2013ProjectsWin32DrawWin32DrawWin32Draw.obj Win32Draw
Error 3 error LNK2019: unresolved external symbol __imp__CreatePen@12 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) C:UsersJonathanDocumentsVisual Studio 2013ProjectsWin32DrawWin32DrawWin32Draw.obj Win32Draw
Error 4 error LNK2019: unresolved external symbol __imp__CreateSolidBrush@4 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) C:UsersJonathanDocumentsVisual Studio 2013ProjectsWin32DrawWin32DrawWin32Draw.obj Win32Draw
Error 5 error LNK2019: unresolved external symbol __imp__DeleteObject@4 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) C:UsersJonathanDocumentsVisual Studio 2013ProjectsWin32DrawWin32DrawWin32Draw.obj Win32Draw
Error 6 error LNK2019: unresolved external symbol __imp__Ellipse@20 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) C:UsersJonathanDocumentsVisual Studio 2013ProjectsWin32DrawWin32DrawWin32Draw.obj Win32Draw
Error 7 error LNK2019: unresolved external symbol __imp__Rectangle@20 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) C:UsersJonathanDocumentsVisual Studio 2013ProjectsWin32DrawWin32DrawWin32Draw.obj Win32Draw
Error 8 error LNK2019: unresolved external symbol __imp__SelectObject@8 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) C:UsersJonathanDocumentsVisual Studio 2013ProjectsWin32DrawWin32DrawWin32Draw.obj Win32Draw
Error 9 error LNK2019: unresolved external symbol __imp__GetMessageW@16 referenced in function _wWinMain@16 C:UsersJonathanDocumentsVisual Studio 2013ProjectsWin32DrawWin32DrawWin32Draw.obj Win32Draw
Error 10 error LNK2019: unresolved external symbol __imp__TranslateMessage@4 referenced in function _wWinMain@16 C:UsersJonathanDocumentsVisual Studio 2013ProjectsWin32DrawWin32DrawWin32Draw.obj Win32Draw
Error 11 error LNK2019: unresolved external symbol __imp__DispatchMessageW@4 referenced in function _wWinMain@16 C:UsersJonathanDocumentsVisual Studio 2013ProjectsWin32DrawWin32DrawWin32Draw.obj Win32Draw
Error 12 error LNK2019: unresolved external symbol __imp__DefWindowProcW@16 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) C:UsersJonathanDocumentsVisual Studio 2013ProjectsWin32DrawWin32DrawWin32Draw.obj Win32Draw
Error 13 error LNK2019: unresolved external symbol __imp__PostQuitMessage@4 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) C:UsersJonathanDocumentsVisual Studio 2013ProjectsWin32DrawWin32DrawWin32Draw.obj Win32Draw
Error 14 error LNK2019: unresolved external symbol __imp__RegisterClassExW@4 referenced in function "unsigned short __cdecl MyRegisterClass(struct HINSTANCE__ *)" (?MyRegisterClass@@YAGPAUHINSTANCE__@@@Z) C:UsersJonathanDocumentsVisual Studio 2013ProjectsWin32DrawWin32DrawWin32Draw.obj Win32Draw
Error 15 error LNK2019: unresolved external symbol __imp__CreateWindowExW@48 referenced in function "int __cdecl InitInstance(struct HINSTANCE__ *,int)" (?InitInstance@@YAHPAUHINSTANCE__@@H@Z) C:UsersJonathanDocumentsVisual Studio 2013ProjectsWin32DrawWin32DrawWin32Draw.obj Win32Draw
Error 16 error LNK2019: unresolved external symbol __imp__DestroyWindow@4 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) C:UsersJonathanDocumentsVisual Studio 2013ProjectsWin32DrawWin32DrawWin32Draw.obj Win32Draw
Error 17 error LNK2019: unresolved external symbol __imp__ShowWindow@8 referenced in function "int __cdecl InitInstance(struct HINSTANCE__ *,int)" (?InitInstance@@YAHPAUHINSTANCE__@@H@Z) C:UsersJonathanDocumentsVisual Studio 2013ProjectsWin32DrawWin32DrawWin32Draw.obj Win32Draw
Error 18 error LNK2019: unresolved external symbol __imp__DialogBoxParamW@20 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) C:UsersJonathanDocumentsVisual Studio 2013ProjectsWin32DrawWin32DrawWin32Draw.obj Win32Draw
Error 19 error LNK2019: unresolved external symbol __imp__EndDialog@8 referenced in function "int __stdcall About(struct HWND__ *,unsigned int,unsigned int,long)" (?About@@YGHPAUHWND__@@IIJ@Z) C:UsersJonathanDocumentsVisual Studio 2013ProjectsWin32DrawWin32DrawWin32Draw.obj Win32Draw
Error 20 error LNK2019: unresolved external symbol __imp__LoadAcceleratorsW@8 referenced in function _wWinMain@16 C:UsersJonathanDocumentsVisual Studio 2013ProjectsWin32DrawWin32DrawWin32Draw.obj Win32Draw
Error 21 error LNK2019: unresolved external symbol __imp__TranslateAcceleratorW@12 referenced in function _wWinMain@16 C:UsersJonathanDocumentsVisual Studio 2013ProjectsWin32DrawWin32DrawWin32Draw.obj Win32Draw
Error 22 error LNK2019: unresolved external symbol __imp__GetSystemMetrics@4 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) C:UsersJonathanDocumentsVisual Studio 2013ProjectsWin32DrawWin32DrawWin32Draw.obj Win32Draw
Error 23 error LNK2019: unresolved external symbol __imp__UpdateWindow@4 referenced in function "int __cdecl InitInstance(struct HINSTANCE__ *,int)" (?InitInstance@@YAHPAUHINSTANCE__@@H@Z) C:UsersJonathanDocumentsVisual Studio 2013ProjectsWin32DrawWin32DrawWin32Draw.obj Win32Draw
Error 24 error LNK2019: unresolved external symbol __imp__GetDC@4 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) C:UsersJonathanDocumentsVisual Studio 2013ProjectsWin32DrawWin32DrawWin32Draw.obj Win32Draw
Error 25 error LNK2019: unresolved external symbol __imp__ReleaseDC@8 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) C:UsersJonathanDocumentsVisual Studio 2013ProjectsWin32DrawWin32DrawWin32Draw.obj Win32Draw
Error 26 error LNK2019: unresolved external symbol __imp__BeginPaint@8 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) C:UsersJonathanDocumentsVisual Studio 2013ProjectsWin32DrawWin32DrawWin32Draw.obj Win32Draw
Error 27 error LNK2019: unresolved external symbol __imp__EndPaint@8 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) C:UsersJonathanDocumentsVisual Studio 2013ProjectsWin32DrawWin32DrawWin32Draw.obj Win32Draw
Error 28 error LNK2019: unresolved external symbol __imp__LoadCursorW@8 referenced in function "unsigned short __cdecl MyRegisterClass(struct HINSTANCE__ *)" (?MyRegisterClass@@YAGPAUHINSTANCE__@@@Z) C:UsersJonathanDocumentsVisual Studio 2013ProjectsWin32DrawWin32DrawWin32Draw.obj Win32Draw
Error 29 error LNK2019: unresolved external symbol __imp__LoadIconW@8 referenced in function "unsigned short __cdecl MyRegisterClass(struct HINSTANCE__ *)" (?MyRegisterClass@@YAGPAUHINSTANCE__@@@Z) C:UsersJonathanDocumentsVisual Studio 2013ProjectsWin32DrawWin32DrawWin32Draw.obj Win32Draw
Error 30 error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup C:UsersJonathanDocumentsVisual Studio 2013ProjectsWin32DrawWin32DrawMSVCRTD.lib(crtexe.obj) Win32Draw
Error 31 error LNK1120: 30 unresolved externals C:UsersJonathanDocumentsVisual Studio 2013ProjectsWin32DrawDebugWin32Draw.exe Win32Draw
这是怎么回事?!?!
解决问题的最简单方法可能是创建一个新的Visual Studio项目,在该项目中您可以小心地创建一个GUI项目。
这将添加最常见的库。
一个更通用的解决方案是负责事情,将您需要的每个库添加到链接器设置中。Microsoft的文档名为MSDN Library,可在线获取,也可作为本地帮助下载,列出了每个函数所需的标头和库。当将来出现这种错误时,您只需阅读文档即可。
关于
"
unresolved external symbol _main referenced
…请注意,没有必要也没有理由使用Microsoft的非标准启动功能WinMain
(或tWinMain
)。使用标准的C++main
函数。对于GUI子系统,对于Microsoft的工具,您必须指定入口点mainCRTStartup
,因为默认情况下Microsoft的工具是非标准的(供应商锁定等等)。
相关文章:
- 为什么"do while"循环不断退出,即使条件计算结果为 false?
- 为什么在全局范围内使用"extern int a"似乎不行?
- 为什么在popback()操作之后,它仍然打印完整的矢量
- 为什么随机数生成器不在void函数中随机化数字,而在main函数中随机化
- 为什么两个不同的未命名名称空间可以共存于一个cpp文件中
- 为什么会发生堆损坏
- 为什么使用 "this" 指针调用派生成员函数?
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 为什么比较运算符如此快速
- 为什么 Serial.println(<char[]>);返回随机字符?
- 为什么这个运算符<重载函数对 STL 算法不可见?
- 为什么不;名字在地图上是按顺序排列的吗
- 我的字符计数代码计算错误.为什么
- 为什么在没有显式默认构造函数的情况下,将另一个结构封装在联合中作为成员的结构不能编译
- 为什么我的C#代码在调用回C++COM直到Task时会暂停.等待/线程.加入
- 为什么在C++中使用私有复制构造函数与删除复制构造函数
- 为什么野牛仍在使用"int yylex(void)",却找不到"int yylex(YYS
- 为什么 std::unique 不调用 std::sort?
- 既然存在危险,为什么项目要使用-I include开关
- 正在发布VS2013链接器错误(Win32API)..为什么?