|
|
<br />
#pragma comment(linker, "/FIXED:NO /OPT:NOWIN98")<br />
#pragma comment(linker,"/ENTRY:main /FILEALIGN:512 /MERGE:.rdata=.text /MERGE:.data=.text /SECTION:.text,EWR /IGNORE:4078")
I pretty much use it in everything i do...
although i wouldnt recommend you change the entry point "/ENTRY:main "...Avoid that if your app uses command lines or uses Parameters from WinMain or DllMain...Consider this a Warning...
You Should also use Matt Pietrek's LibcTiny Library...
-Piece!
-st0le [st0le'n'stuff softwarez!]
http://st0lenc0des.googlepages.com/
modified 20-Oct-19 21:02pm.
|
|
|
|
|
using /align:4096 is virtually the same as using /opt:nowin98 except that you don't get any warning
reason: default align is already 4096 (which you should keep). the size reduction is because the linker then uses a file align of 512 which is what you get with /opt:nowin98.
|
|
|
|
|
|
I use /Align:256, /Align:128 or even /Align:16 options and find that the linker produce smaller executables. The last option produces the Hello World program of just 688 bytes and it runs well. But I don't know if these non-standard align options affect the loading time of the executables. Is there anyone can give me an answer?
|
|
|
|
|
There are something that can be improved about those mentioned in the above article.
First, The built release exe file are dependent on the msvrct.dll(build with vc++6.0) or msvcr71.dll(build with vc++2003) etc.
Second, the exe file is about 3K, but this can still be reduced to about 1K.
Solutions:
1. The program doesn't use any c runtime library functions, except WinMainCRTStartup(the default program entry point). So if we assign our own entry point function, we can strip the c runtime library completely.
Improvements:
(1). Remove the msvcrt.lib in the vc++'s linker/input entry.
(2). Add "#pragma comment(linker, "/Entry:WinMain") " just below "#include "stdafx.h" ".
2. For this program we can merge the .text section with .rdata section.
Improvements:
Add the following statement just under "#include "stdafx.h" ":
#pragma comment(linker, "/Merge:.rdata=.text")
So the souce code is like:
#include "stdafx.h"
#pragma comment(linker, "/Entry:WinMain")
#pragma comment(linker, "/OPT:NOWIN98")
#pragma comment(linker, "/Merge:.rdata=.text")
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MessageBoxW(NULL, L"Hello World", L"Hello World", MB_OK);
return 0;
}
Build the solution, then the release built exe will be just 1K and isn't dependent on c run-time library.
Ehancing everyday.
|
|
|
|
|
I use the Vs2002 and found the reduced size are more than 50K.
|
|
|
|
|
You are 'Dynamic' linking with the (Microsoft) run time library (312K), which is NOT much better then linking with the MFC library. And like the MFC library you don't know what version the end-user has installed on their system, so you have the over head of checking/installing anyway!
|
|
|
|
|
Can I use it with DLLs the same way, too?
thanx // bass
|
|
|
|
|
I had the same challenging task and i had to make an exe file below 40KB and no MFC because have to run on all WinOSs and less frequent users dont have MFC on their Win98 or Win95 computers.
By the way MFC does reduce the size a bit but still not good enough.
Thanks a lot my exe file reduced to 24 from 56KB or else my client would have killed.
Thanks again I am really happy.
In my dream, I was dorwning my §orrow§
But my §orrow§, they learned to §wim
|
|
|
|
|
I do the samethings but NOTHING change,any suggestion about what the hell is going on?
Mazy
Don't Marry a Person You Can Live With...
Marry Someone You Can Not Live Without
|
|
|
|
|
Hi Mazy,
And sorry for being late, I was getting notifications but could not attend to ur problem as I was busy with my work. You seem to have tough time reducing the size of ur exe file.
Well, first of all, this article was written for developer studion 6.0. I have not tried these options in VC 7 yet, so I can not say any thing about it. Secondly, these options will/may not have any dramatic effect on the MFC projects. Thirdly, these options are workable for release builds only, not the debug builds.
Please make it sure that you are not trying do the job out side the scope of this article.
Best of luck.
|
|
|
|
|
It will not work if the project is calling the function(s) in the lib(s) that has been ignored.
|
|
|
|
|
would you please tell me the link of that Microsoft news threads ?
thanks in advance
Mazy
You can find a solution (even a foolish one) for all problems (even big ones)
|
|
|
|
|
I use VC7 .I could not find any place to delete those libarary and also no place to type "/ALIGN:4096" in project properties?!(I typed those library in "Ignore specific library" but nothing changed in .EXE release file?)
Can anybody tell me where the hell they are?
Mazy
You can find a solution (even a foolish one) for all problems (even big ones)
|
|
|
|
|
You should take a look at this article before using any exe compressor.
http://www.jrsoftware.org/striprlc.htm#execom
|
|
|
|
|
Always on the lookout for ways to reduce the size of the resulting program, I did some unit testing with the various linker options that appear to affect it:
/align:4096
/filealign:512
/opt:nowin98
The end result of using any single one (or any combination) will result in the exact same output. The output is larger, of course, if non of them are used!
I suspect that the action that /align is doing when you use it is to turn on the 512-byte file align flag, either by design or oversite on M$'s part. How long this will continue to be this "side effect" of /align is anyone's guess - they could fix it in the next update!
|
|
|
|
|
What was the newsgroup you got your inital information from?
The default for /ALIGN is already 4096; simply specifying this should not make any difference, since you're not changing anything.
Leaving out the M$ Visual C RunTime Lib may cause problems in your program not linking at all!
Also, you might want to check out an existing article here on CodeProject about optimizing and linking to get the program size down, titled Aggressive Optimizations.
|
|
|
|
|
I applied the suggested changes to a small 50 line console program to create NTFS 2000 hard links and the size was reduced from 28k, default release settings, to 3k.
I looked up the info on /ALINGN and indeed the documentation states that the default is 4k. However, removing this directive increased the exe from 3k to 16k.
This seems like a >great< method to make very tiny console apps
|
|
|
|
|
You can get the same results using /opt:win98 or /filealign:512 - M$ left lots of ways to do this it seems.
|
|
|
|
|
Yes, by default it is 4096 or 4K but size does change if you mention it in linker options. I dont know why it is so, but it is that way
|
|
|
|
|
Look at
http://wildsau.idv.uni-linz.ac.at/mfx/upx.html
there you can find a very good tool for compressing exes, dlls, ocxs etc.
Best of all: Its freeware, and comes with source code!
|
|
|
|
|
This link dosent work???? any substitute link for the prior?
|
|
|
|
|
http://upx.sourceforge.net/
...Publikum noch stundenlang, wartete auf Bumerang.
|
|
|
|