cm007
cm007

Reputation: 1392

Difference between Microsoft compiler and GNU compiler, in terms of output executable file size

Suppose I have the following program:

#include <stdio.h>
int main()
{
    printf("This is a sample C program.\n");
    return 0;
}

If I compile it with the Microsoft compiler (cl.exe /O1 sample.c) on a Windows 7 32-bit machine, then it outputs an executable file that is 44 KB.

If I compile it with the GNU compiler (gcc sample.c) on a CentOS 64-bit machine, then it outputs an executable file that is 6 KB.

Generally speaking, why is there such a big difference in file size for this small program? Why does it take Windows 44 KB just to print a line and exit?

Upvotes: 0

Views: 392

Answers (2)

Sangeeth Saravanaraj
Sangeeth Saravanaraj

Reputation: 16597

Apart from the links provided above, I feel this will also help you to understand on what happens when we compile using gcc!

Upvotes: 0

Nelson
Nelson

Reputation: 1032

If you use the /MD switch with cl.exe, it will dynamically link against msvcrt (the Microsoft C runtime library) and use the msvcrt.dll (and you will get a comparable executable size of 6KB), otherwise the code from the C library is statically linked into your executable increasing the size of the executable.

Your gcc compiler on CentOS is setup to dynamically link against the C library by default.

Upvotes: 2

Related Questions