Win32 program Link error: LNK2019

Hi folks,

I want to know how to compile Win32 program using MS 32-bit C/C++ Compiler (cl.exe) of Visual Studio 2008 professional. But I got the LNK2019 error (unresulved external simbol__imp__MessageBoxA) when compiling the following code (Simple.c) with "cl Simple.c" command:
1
2
3
4
5
6
#include<windows.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
	MessageBox(NULL, TEXT("Goodbye, cruel world!"), TEXT("Note"), MB_OK);
	return 0;
}

What was wrong with it? (In VS 2008 IDE, the above code does compile, but from VS 2008 command window it does not.)
Last edited on
You're not linking with user32.lib
Then how can I link it with user32.lib? kbw, can you show me the command? Thank you.
Last edited on
cl -W4 g.cpp -l user32.lib

Remeber to run the appropriate vsvars.bat in your console before running cl. If you're doing this in Visual Studio, the include/lib paths, libraries and so on are already setup in the project by the wizard.
Last edited on
Hey man make it clear. I have same problem.
Yap.I got the answer.Write
<code>#progma comment(lib,"user32.lib");</code>
after<code> #include<windows.h></code>
If you're using the IDE, add it to the linker section. If should be set up by default, not in your code.
kbw's answer solved my problem as follows:
(1) launch Visual Studio 2008 Command Window;
(2) cl Simple.c user32.lib // Simple.c being my win32 program I originally posted at the top of this thread
Done
Last edited on
Topic archived. No new replies allowed.