Reputation:
This is my first question here, i'm a big fan and found many solutions in stackoverflow, so many thanks to all. I would be happy if my question is one that is worth time.
I'm using Windows 7 and Microsft Visual C++ 2010 Express. The C code is:
int main()
{
return 0;
}
When compiling the code with the ide, with project properties -> C/C++ -> CodeGeneration -> Runtime Library = /MTd option the exe size is 395,264 bytes. When compiling the program under console with cl.exe using the Visual Studio Command Prompt "cl test.c" the exe size is 31,744.
SIZES: 1. 395,264 2. 31,744
Any idea why there is so big differences in the sizes?
Thank You.
Upvotes: 0
Views: 1292
Reputation: 8323
Compiling in VS with the /MTd
option is building your program with multi-threaded debug libraries in the final executable, which will cause a size increase in your binary for those extra objects.
The compile command of just the source file will not result in any additional object code being linked, and will result in a smaller exe.
See this page for further reference
When I use the same source code, with the same compiler options, I get a final size of 391K. From the command line, I get the following:
cl MyProg.cpp -> 31K
cl /MTd MyProg.cpp -> 137K
If you include some of the other options that the IDE is including for you, then you get something like this:
cl /MTd /Gm /ZI /EHsc MyProg.cpp -> 378K
It's simply a matter of the difference between the build commands that is causing your difference.
Upvotes: 2
Reputation: 27538
Because:
/M
family of options.Somewhere in the IDE, go to your test project's properties. Open Configuration Properties -> C/C++ -> Command Line and Configuration Properties -> Linker -> Command Line. This will show you all options with which your IDE invokes the compiler and linker.
The mere fact that the IDE uses so many options should tell you that it's not using the tools' defaults.
If you go to the command line and invoke the compiler and linker with the same options shown in the IDE, then the resulting executable should be 100% identical.
Upvotes: 2