Exe build by Code blocks is almost 57 times larger than the same code build by Visual studio

This code:

#include <iostream>
using namespace std;

int main()
{
    cout << "Hello world!\n";
    return 0;
}

when comiled give size 457KB in Code::Blocks with GCC 4.4.1 and only 8KB (eight) in VS2010. Both compilers optimized for size.

Anyone knows why such a difference?

Upvotes: 3

Views: 2238

Answers (2)

Kartikya
Kartikya

Reputation: 453

You are right, the executable by gcc is obviously larger, in your case 57 times larger than that built by vc++.

The main reason is the one made with GCC won't require any external dependencies to run while the one made with VS2010 would need at least its runtime files to be present on the system.

For instance, say you try it on some friend's computer with no vs2010 installed, rather try earlier OS like XP with no chance of having VS2010 runtimes even.

The one built with GCC will have no problems while the one made with VS2010 would throw an error of missing runtime file ( dependency ).

Hope this helped, if it didn't or you have any other question in your mind, feel free to ask and I'll be glad to help :)

Upvotes: 1

Erik
Erik

Reputation: 91320

This is due to the c++ standard library being linked statically by g++, whereas VS will link it dynamically. A quick check using gcc under cygwin gives me approximately same sizes, and the resulting exe only import some C functions.

#include <stdio.h>
int main() {
  printf("Hello world\n");
  return 0
}

On the other hand, this application compiled to the same minimal EXE under gcc, as it does not require any c++ functionality.

Upvotes: 6

Related Questions