cl.exe unresolved external symbol

Just need to get in the know-how on building Win32 programs using the command line compiler cl. When I run it, I get the messages
main.cpp
Microsoft (R) Incremental Linker Version 10.00.30319.01
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:main.exe 
main.obj 
main.obj : error LNK2019: unresolved external symbol __imp__DispatchMessageW@4 referenced in function _WinMain@16
main.obj : error LNK2019: unresolved external symbol __imp__TranslateMessage@4 referenced in function _WinMain@16
main.obj : error LNK2019: unresolved external symbol __imp__PeekMessageW@20 referenced in function _WinMain@16
main.obj : error LNK2019: unresolved external symbol __imp__ShowWindow@8 referenced in function _WinMain@16
main.obj : error LNK2019: unresolved external symbol __imp__CreateWindowExW@48 referenced in function _WinMain@16
main.obj : error LNK2019: unresolved external symbol __imp__AdjustWindowRect@12 referenced in function _WinMain@16
main.obj : error LNK2019: unresolved external symbol __imp__RegisterClassExW@4 referenced in function _WinMain@16
main.obj : error LNK2019: unresolved external symbol __imp__LoadCursorW@8 referenced in function _WinMain@16
main.obj : error LNK2019: unresolved external symbol __imp__DefWindowProcW@16 referenced in function "long __stdcall WindowProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WindowProc@@YGJPAUHWND__@@IIJ@Z)
main.obj : error LNK2019: unresolved external symbol __imp__PostQuitMessage@4 referenced in function "long __stdcall WindowProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WindowProc@@YGJPAUHWND__@@IIJ@Z)
main.exe : fatal error LNK1120: 10 unresolved externals


Any idea of whats up? Is there a certain link parameter I need, like /LIBPATH, if so, where's the directory/value?

EDIT: for reference, cl.exe is the Microsoft c++ compiler that comes with Visual C++ express and Visual Studio
Last edited on
You need user32.lib added as linker input. See cl.exe command-line switches.
Thanks, sorry for late reply, but that worked, I just have to link them together, ie
link main.obj "C:\Program Files\...\User32.Lib"


This works! any way to combine the "cl main.cpp" and "link main.obj "C:\...\User32.Lib" into one command would be nice, but this is great
Last edited on
If your path is set up correctly, you ought to be able to specify:
 
cl main.cpp user32.lib

I'll double check the exact syntax when I get back on a Windows box.
Check your linker documentation for how to setup libraries directories.
Documentation isn't exactly available, since the cmd compilers aren't really intended to be used (I don't think, and I've got this feeling from reading what I could abt Microsoft cmd compilers)
To see the options, run
 
cl /?

cl was run with make files long before the was a decent IDE.
I understand that VS makefiles are now xml based, and the make program equivalent is MSBuild (used to be nmake). Unless things have changed an enormous amount since I last looked at it, when you push the button on your MS IDE, cl.exe is run on the command line with the various settings input just as if you had typed it yourself. The compiler very much is intended to be run from the command line, but the user is not intended to have anything to do with it.
Topic archived. No new replies allowed.