Reduce the EXE (DLL) code, mainly from the following aspects:
1. Code quality. Consider refactoring when you try to copy & paste code. Copying Code not only makes it difficult to modify and maintain the code, but also increases the size of the final executable file.
2. try to use the dynamic link library of the system, such as the required DLL for each version of kernel32.dll. such as some DLL, such as msvcrt. DLL does not exist on Win98. however, it is often unavoidable for projects to use other libraries, such as STL.
3. compiler option (especially the linker option) optimization. use appwizards to create a hello, world GUI Win32 program without any code. After release is compiled, it also has 40kb. you can use denpendency Walker to open it and find that many functions are referenced in kernel32.dll, but not in your code, this is because the default linker links the C Runtime Library to your code statically, and you may not use any C Runtime library function. therefore, the first step is to hook ignore default libraries in the linker option (this will make the linker not connected to the default CRT ). add the library you want to reference, such as kernel32.lib, and set entrypoint (because the _ maincrtstartup or _ winmaincrtstartup function in C Runtime libray is used by default ). step 2: add the/OPT: ref/OPT: ICF/OPT: nowin98 last parameter to reduce the number of EXE files. in addition, it is the optimization of the merge section, that is,. RDATA. text segments are merged. but this optimization is not recommended. the last step is the optimization of alignment./filealign (can only be used on vc6). By reducing this value, you can remove unnecessary code generated by alignment in the code. for more information, see the second link of references. compiler Options, minize code size and global optimization + favor small code can also be reduced, but usually not much.
4. EXE compressor. ASPack and upxshell are the most commonly used EXE compressor, which can usually reduce the number of executable files by about half.
The above is my article"How to reduce the size of executable files-minimize your excutables"Found, the author is for the VC program under Win32, but a lot of truth is the same. The following describes a WM Executable File compression tool:
Upx4ppc is a shelling and shelling tool used on PPC. In short, it can compress the execution file (exe) and dynamic link library (DLL ), the compression rate is around 50% (for example, the main program pocketmusic5.06 is 800 K, and only 313 K after compression), which greatly saves the memory space of our users and can also be used in custom Rom, for example, compressing DLL files in office6.1
★Instructions for use:
1. The software is a green version and can be stored anywhere, including the Chinese path. However, the path to the target file to be processed cannot contain the Chinese name, for example, 'sd card/cmd.exe 'cannot be handled correctly.
2. Note that backup before compression is very important. Not all files can be used normally after compression. Although it can be used for decompression after compression, it is better to save the original file, confirm that the compressed software is used normally and then delete the backup file.
3. For the upx4ppc decompression function, only files of the same version can be decompressed, but not backward compatible.
4. In terms of compression, the "maximum" compression ratio is higher than the "highest speed", but it is not absolute. For example, nfbrowser35.dll uses the "maximum" compression, but the "highest speed" compression is not valid.
★Known files that cannot be compressed
PPC has a large number of software. I hope you can stick the software that cannot be used normally after compression to avoid detours.
1. Resource Manager RESCO explorer. After compression, the icon is abnormal and some text cannot be displayed.
2. The language file mui0000804.dll of the music player pocketmusic. After compression, the text is not displayed normally.
3. System Tool sktools, cannot be started after compression
4. the browser picselbrowser cannot be started after compression
5. the browser netfront3.5 language file nfb35res. dll. Some compressed text cannot be displayed.
6. The dictionary tool mdict cannot compress icons.
7、super-frequency software xcpuscalar.exe, cannot be started after compression
★Compression principle: It is to first compress the executable file as data, of course, it is not completely the data, and then the attachment is placed behind a small decompression code; in this way, the file is very small, at runtime, the first step is to decompress the code, decompress the real file to the memory, and then run. The disadvantage is that it consumes a little more memory to run, but it is very small and can be ignored; it also consumes time and needs to be decompressed, so the program will be slower to start, but generally cannot be noticed.