-
1 Attachment(s)
Small Apps
I was able to create a 16kb basic application with the tips here:
http://www.mvps.org/user32/nocrt.html
This poses a couple of problems.
Since all the default libraries are being ignored, using math.h or any other header (have not tested) then the linker complains trying to use a function from the library. The attached project uses sinf(float) from math.h but it will not link. I am not sure if you have to link to another library file and what it is called if so (not math.lib).
Secondly, I have no idea how to write an operator function for 'using' and 'namespace' . Adding #include<sstream> and using namespace std; will not link.
Any ideas?
-
Use CRT. Ignoring it only makes sense if you rely completly on the WinAPI functions.
-
I revived this thread because I have been able to compile the following code down to 16kb from the default 36kb in VC++ release build.
Make sure "Ignore all default libraries" is checked and you add msvcrt.lib, kernel32.lib, and user32.lib to link.
Code:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){
MessageBox(0, "Hello, World!", "Hello", 0);
return 0;
}
Now this code won't link unless you include msvcprt.lib in the link.
Code:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <string>
using namespace std;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){
string str = "Hello, World!";
MessageBox(0, str.c_str(), "Hello", 0);
return 0;
}
This code won't link because I don't know the .lib(s)
Code:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <sstream>
using namespace std;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){
ostringstream oss;
return 0;
}
Now, my question is, what are the other libraries for the rest of the STL?
I at least need the .lib for <iostream> and <sstream> since I use these quite often.
-
1 Attachment(s)
-
All of the STL should be in the compiler-specific version of msvcprt.lib. I'm not sure if VC7 uses another name for it (it does for the dll).
It should be possible to reduce the size even more by just doing this:
Code:
int __stdcall MessageBoxA(void* hWnd, const char *szText, const char *szCaption, unsigned long flags);
void Entry()
{
MessageBoxA((void*)0, "", "", 0);
}
Put it in a .c file, not .cpp. In the linker settings you must set the entry point to Entry and the ONLY lib to include is user32.lib
0 is the value of MB_OK.
Maybe this call would require even less space:
Code:
void Entry()
{
long l = 0;
MessageBoxA((void*)0, &l, &l, 0);
}
because it totally omits a data segment.
Or maybe in assembler:
Code:
__declspec(naked) void Entry()
{
_asm {
push 0
push esp
push dword ptr [esp]
push 0
call MessageBoxA
}
}
The entire app should only consist of these directives + the include stub for MessageBoxA + the PE header. Should be about 40 bytes + the header.
Of course, if you want it REALLY small you're better off with MASM and pure assembler.
-
If you link to all these libraries, all of the STL that I have tested seems to work with the app:
libc.lib libcp.lib msvcrt.lib kernel32.lib user32.lib
It bloats the app from 16.0kb to 72.0kb though!
I guess that's the price you pay for the ease of STL.
If you don't need the STL though, ...
-
hmmm...
I thought libc.lib is just the static version of the CRT library - and msvcrt.lib is the import lib for the dynamic version - strange that it works including both...
libcp.lib is the static version of the C++ runtime.