I was testing this simple c++ code on my Windows 8.1, Intel i7-3517U 64 bit laptop with GCC 4.8.2.
#include<iostream>
using namespace std;
int main(int argc, char **argv){
cout << "This test code will simply display any arguments passed." << endl ;
for(int i=0; i<argc; i++){
cout << argv[i] << endl ;
}
return 0 ;
}
Surprisingly, after compiling, the executable turned out to be of 5905KB. Out of curiosity, i tried compiling the same file with the same GCC version on Linux Fedora 20 64 bit machine. And the executable was just 9KB.
After doing various optimization using g++ -Ox -o fileWithOx.exe file.cpp
(x=1,2,3,s), Windows executable were nearly same in size. After doing some research, and following MinGW's advise i tried compiling them without debugging information using strip g++ -s -o fileWithStrip.exe file.cpp
, but the executable was still 597KB large.
While on the other hand, Linux executable were of just 6-13KB for same options.
Doing some experiments, some more research & stack overflowing, i was nearly convinced that the gigantic size is due to iostream linking to many other header files and/or generating some initialization code.
But my doubt is that iostream is used both in Windows as well as in Linux. Then why so much difference in size? I know that Windows and Linux executable work differently. But 655 times bigger, isn't this a bit extreme?