Advertisement

Linker Errors

Started by September 18, 2014 05:53 PM
2 comments, last by Buckeye 10 years, 4 months ago
Ok so I have two linker errors and I don't seem to understand what exactly they mean.
Can somebody shade some light on them:
LNK2019: unresolved external symbol "long __stdcall MainWindowProc(struct HWND__ *,unsigned int,unsigned int,long)" (?MainWindowProc@@YGJPAUHWND__@@IIJ@Z) referenced in function _WinMain@16
I solved the Procedure function: it was an incorrect reference to the window class' lpfnWndProc parameter
LNK2019: unresolved external symbol _D3D11CreateDeviceAndSwapChain@48 referenced in function "protected: bool __thiscall DXBase::InitDirect3D(void)" (?InitDirect3D@DXBase@@IAE_NXZ)
If code is needed replay and I will upload

The first error appears (guessing) because you create** a window referencing MainWindowProc as the window procedure but that function doesn't appear (with that signature, anyway) in your code anywhere.

The second error appears to result from not linking in d3d11.lib, or your library path is incorrect***. Take a look at the docs for "D3D11CreateDeviceAndSwapChain." At the bottom of the page is listed "Requirements." Under that is a table listing the header you must "#include" and the library you must link.

**EDIT: actually, it's likely in the WNDCLASS(EX) struct in your RegisterClass(Ex) call.

If you have MainWindowProc in the WNDCLASS, somewhere you must have a function:

LRESULT CALLBACK MainWindowProc(HWND, UINT, WPARAM, LPARAM) { ... }

with those parameters.

***EDIT2: if your library path is incorrect and you have linked d3d11.lib, you'll get a "library not found" type error instead. Sorry about that.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Advertisement

The first error appears (guessing) because you create** a window referencing MainWindowProc as the window procedure but that function doesn't appear (with that signature, anyway) in your code anywhere.

The second error appears to result from not linking in d3d11.lib, or your library path is incorrect***. Take a look at the docs for "D3D11CreateDeviceAndSwapChain." At the bottom of the page is listed "Requirements." Under that is a table listing the header you must "#include" and the library you must link.

**EDIT: actually, it's likely in the WNDCLASS(EX) struct in your RegisterClass(Ex) call.

If you have MainWindowProc in the WNDCLASS, somewhere you must have a function:

LRESULT CALLBACK MainWindowProc(HWND, UINT, WPARAM, LPARAM) { ... }

with those parameters.

***EDIT2: if your library path is incorrect and you have linked d3d11.lib, you'll get a "library not found" type error instead. Sorry about that.

Thank you for the quick replay. The problem was coming from the fact that I haven't included the d3d11.lib in the Linker->Input->Additional Dependecies

One quick question: I've seen many people use the '#pragma comment(lib,"<name of library>")'. what is this and why is this needed?

#pragma comment(lib...

is an alternate way to specify linker options in MSVS. I use that, for instance, in my folder of "reusable" code snippets to remind me what library needs to be linked.

Discussed here.

EDIT: Thanks for posting the reason/solution for the problem.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

This topic is closed to new replies.

Advertisement