For the fun, I want to create a (working) executable that doesn’t depend on the CRT. It wasn’t that hard after reading some articles, so I settled on:
/* test.c */
int main(){
return 0;
}
...
/* Compiling & Linking: */
cl /c /O2 /Ox /Os test.c
link /ENTRY:main /NODEFAULTLIB /SUBSYSTEM:WINDOWS /ALIGN:16 /ignore:4108 test.obj
So far so good, but I would like to be able to call the functions of Windows API. For example, how should I link the following piece of code?:
#define UNICODE
#include <windows.h>
int main(){
MessageBox
(NULL, TEXT("Hello Stackoverflow!"), TEXT("Hello Stackoverflow"), MB_OK);
return 0;
}
I read the following articles but couldn’t come up with a solution:
Minicrt, Small Programs, Tiny PE, Techniques for reducing Executable size.
Thanks in advance 🙂
Link against
user32.libLook up in MSDN which library the function belongs to, and link against it.