Lowering build size

孤街浪徒 提交于 2019-12-02 08:37:11

If you're only going to display a MessageBox, you don't need to link to any static libraries.

#include <windows.h>

void entry(void) {    
    MessageBox(NULL, "Hello, World!", "", MB_OK);
    ExitProcess(0);
}

Compile and link using VC++2013, with the following command line:

cl /O1 /GS- hello32.c /link /nodefaultlib /entry:entry /subsystem:windows user32.lib kernel32.lib

At least for me (with VC++ 2013) that produces an executable of 2560 bytes (that depends only on core Windows DLLs, so it shouldn't require anything extra to run on even the most bare-bones system).

As your main intention is to keep size in control, dll is way to go.

As far as your missing dll is concerned it can be addressed. If you are using standard libary missing error then its good idea to install redistributable on machine where you are running application.

Redistributable for VS2013

If you don't use MFC etc. you can

#define WIN32_LEAN_AND_MEAN
#include <Windows.h>  

to reduce size of your code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!