**My main assignment is to make the EXE file size as smaller as possible. ** I'm currently working on program which make use of:
#include <iostream>
#include <vector>
#include <string>
#include <array>
#include <windows.h>
#include <bcrypt.h>
#pragma comment (lib, "bcrypt.lib")
#pragma comment (lib, "kernel32.lib")
As I compile and link the code with /MT and /NODEFAULTLIB I get the unresolved external symbols LNK 2001 and 2019 such as:
error LNK2001: unresolved external symbol "const type_info::`vftable'" (??_7type_info@@6B@)
error LNK2001: unresolved external symbol "class std::basic_istream<char,struct std::char_traits<char> > std::cin" (?cin@std@@3V?$basic_istream@DU?$char_traits@D@std@@@1@A)
When I use the default libs I see the libraries it imports objects from:
libcmt.lib
libcpmt.lib
libucrt.lib
libvcruntime.lib
As I understand, those libraries contains the functionality so I must use them and to disable them
But on the other hand, they make my static-linked exe file heavy
What can I do to reduce my EXE file size to the minimum? I thought about changing the functions I use (I mean, stdio.h instead of iostream for example) Any other thoughts and suggestions for steps I can make?
I tried to:
- disable by /NODEFAULTLIB
- using /Gs- so no security will be needed
- using /Os /O1 and other optimazations
I also tried to replace iostream with stdio.h and replaced all std::cout, std::cin and std::cerr with printf() and scanf() It did reduced me like 62KB (from 179KB to 117KB) But as I instructed, I can manage to reduce it even lower