I am just learning c++ and successfully compiled and ran HelloWorld (I do extensive coding in Matlab, and used to code a bit in C but have basically forgotten C).
I am a bit concerned that the executable is over 3MB in size (the .cpp file is below). Is this reasonable? It seems excessive to my untrained eye.
Some details: I am developing within Code::Blocks using gcc, following along the book 'Beginning programming with C++ for Dummies' by Stephen Davis, and using the software that came with the book's CD.
They implied I might try changing some settings in my compiler. I don't really know how to do such things yet, but I did go into 'Project Build Options' I clicked 'Optimize generated code (for size)'. This didn't change anything.
Your compiler is statically linking the runtime (that is, all the functions that implement I/O interfaces and the like are being included in the executable). If you Google a bit you can find what flags to pass to link the runtime dynamically. If you do that, you'll notice that your executable is reduced to a much more reasonable size.
But note that if you're going to be sharing your executables with other people, linking statically is more convenient because you don't need to also pass libraries around.
Helios: thanks. I guess I'll just wait until I understand how to control these flags from within the IDE I am using (code::blocks). I'm literally just starting over with HelloWorld. I did use the -Os flag but it didn't do anything.
But perhaps it's best, for now as I mess around with the very basics, not to worry about it.
It sounds like it is supposed to be large like this, and based on the previous links, as I write larger programs the libraries will stay the same size, so it isn't that big a deal.
It doesn't do anything because that flag is passed to the compiler when it compiles your code. The runtime is already compiled, so there's nothing to optimize.
as I write larger programs the libraries will stay the same size, so it isn't that big a deal.
You could try passing the -s flag to the compiler. It often reduces the size quite a bit but makes debugging impossiblemore difficult so you probably don't want to have it turned on all the time.