Handmade Hero » Forums » Code » I have problems compiling
packetsthief_
Mohammed Salim Boulaajine
2 posts
#16346 I have problems compiling
1 month ago Edited by Mohammed Salim Boulaajine on Sept. 17, 2018, 5:33 p.m. Reason: added error message

Hey, I'm 3 episodes in and I have problems compiling
Here's the error message :
w:\handmade\code>cl win32_handmade.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.15.26726 for x64
Copyright (C) Microsoft Corporation. All rights reserved.

win32_handmade.cpp
Microsoft (R) Incremental Linker Version 14.15.26726.0
Copyright (C) Microsoft Corporation. All rights reserved.

/out:win32_handmade.exe
win32_handmade.obj
win32_handmade.obj : error LNK2019: unresolved external symbol __imp_CreateCompatibleDC referenced in function "void __cdecl Win32ResizeDIBSection(int,int)" ([email protected]@[email protected])
win32_handmade.obj : error LNK2019: unresolved external symbol __imp_DeleteObject referenced in function "void __cdecl Win32ResizeDIBSection(int,int)" ([email protected]@[email protected])
win32_handmade.obj : error LNK2019: unresolved external symbol __imp_StretchDIBits referenced in function "void __cdecl Win32UpdateWindow(struct HDC__ *,int,int,int,int)" ([email protected]@[email protected]@[email protected])
win32_handmade.obj : error LNK2019: unresolved external symbol __imp_CreateDIBSection referenced in function "void __cdecl Win32ResizeDIBSection(int,int)" ([email protected]@[email protected])
win32_handmade.obj : error LNK2019: unresolved external symbol __imp_GetMessageA referenced in function WinMain
win32_handmade.obj : error LNK2019: unresolved external symbol __imp_TranslateMessage referenced in function WinMain
win32_handmade.obj : error LNK2019: unresolved external symbol __imp_DispatchMessageA referenced in function WinMain
win32_handmade.obj : error LNK2019: unresolved external symbol __imp_DefWindowProcA referenced in function "__int64 __cdecl Win32MainWindowCallback(struct HWND__ *,unsigned int,unsigned __int64,__int64)" ([email protected]@[email protected]@[email protected])
win32_handmade.obj : error LNK2019: unresolved external symbol __imp_RegisterClassA referenced in function WinMain
win32_handmade.obj : error LNK2019: unresolved external symbol __imp_CreateWindowExA referenced in function WinMain
win32_handmade.obj : error LNK2019: unresolved external symbol __imp_BeginPaint referenced in function "__int64 __cdecl Win32MainWindowCallback(struct HWND__ *,unsigned int,unsigned __int64,__int64)" ([email protected]@[email protected]@[email protected])
win32_handmade.obj : error LNK2019: unresolved external symbol __imp_EndPaint referenced in function "__int64 __cdecl Win32MainWindowCallback(struct HWND__ *,unsigned int,unsigned __int64,__int64)" ([email protected]@[email protected]@[email protected])
win32_handmade.obj : error LNK2019: unresolved external symbol __imp_GetClientRect referenced in function "__int64 __cdecl Win32MainWindowCallback(struct HWND__ *,unsigned int,unsigned __int64,__int64)" ([email protected]@[email protected]@[email protected])
win32_handmade.exe : fatal error LNK1120: 13 unresolved externals
mmozeiko
Mārtiņš Možeiko
1811 posts / 1 project
#16347 I have problems compiling
1 month ago Edited by Mārtiņš Možeiko on Sept. 17, 2018, 8:20 p.m.

You need to add gdi32.lib and user32.lib import libraries to your linker.

If you see "unresolved external symbol" error in linker, then you need to search where is this symbol. For example, lets take __imp_CreateCompatibleDC. Remove __imp_ prefix and search MSDN for CreateCompatibleDC function. You'll find this: https://docs.microsoft.com/en-us/...ngdi/nf-wingdi-createcompatibledc Scroll to the bottom and check what is written next to "Library"? gdi32.lib! And that is exactly what you need to add to your linker arguments.

You can see Casey explaining and doing this and the end of Episode 1 "Import a library": https://hero.handmade.network/episode/code/day001/#3720
Similar thing happened at end of Episode 2 "Drawing something with WM_PAINT": https://hero.handmade.network/episode/code/day002/#3375

And next time please copy&paste text instead of posting screenshot of text.
packetsthief_
Mohammed Salim Boulaajine
2 posts
#16348 I have problems compiling
1 month ago

Thank you very much, sir!
my bad, I didn't pay enough attention.
I added the text message of the error.
Have a great day.