QUOTE(joske @ 20 May, 2008 - 02:12 AM)

Is this library-usage also the reason that you have to compile the executable separately for each different linux distribution? Because the program links to libraries that can be different on each platform?
No, not really. When you actually run a program, the program will attempt to locate and load the required libraries into memory. If they aren't found, then the program just won't run.
As long as the library has the correct name, the program should be able to locate it. Shared libraries actually have several benefits. Namely, only one copy of the library has to be loaded into memory at one time (IE, several programs can access and use the same library without loading it more then once). You can also provide updates for various programs, by just updating the shared library; although, this can lead to version conflicts.
Compiling programs from the source level provides a few benefits. The main one deal with optimizations. Take SSE for example. If your processor supports said extension, then telling the compiler to use that extension will generally provide better performance, and smaller code. That's why a lot of Linux projects have "configure" scripts (which I hate for various reason...).
One of the nice things about stuff like apt-get is that they do tend to download any dependencies the program may need.
QUOTE(joske @ 20 May, 2008 - 02:12 AM)

And secondly: So, if I understand it well, gcc is not optimized for reusing libraries in Windows. For example VC++ seems to compile programs on Windows more efficiently as compiling the program I posted above with VC++ results in an executable of a about 30kB - 40kB.
About the compiler: I'm pretty new to cross-platform programming. I'm playing around with wxDev-C++, CodeBlocks, and kDevelop. But so far I prefer using a colored text-editor and a command line most. I have a simple bash script which I run, see attachments.
It really depends on the compiler. There are two main Windows GCC ports that I know of,
cygwin and
MinGW. Since you mentioned Dev-C++, and you have it in your script, I assume you are using the MinGW port (which is what Dev-C++ comes with).
In most of my experiences, MinGW actually producers smaller executables then the MS compiler.
Referring to the script, you use *.cpp (which I do as well, and I love it to death). While this is very convenient, it can lead to unnecessary code bloat. For example, take the program in your first post. If you had additional libraries in the directory that code is located in, yet you don't use any of the other code, it will still be compiled into your program along with what it those libraries include.
You can further reduce the size of the executables, if you remove unnecessary includes. Take your first post again.
#include <cstdio>
is doing absolutely nothing, since you don't call any functions from it.
You also have
#include <cstdlib>
for system(). Personally, I frown on the use of system(). While the function is actually a part of the C standard, the results are not portable.
So, with a little revising, you could have this
CODE
//
// Program to convert temperature from Celsius degree
// units into Fahrenheit degree units:
// Fahrenheit = Celsius * (212 - 32)/100 + 32
//
#include <iostream>
using namespace std;
int main(int nNumberofArgs, char* pszArgs[])
{
// enter the temperature in Celsius
int celsius;
cout << "Enter the temperature in Celsius:";
cin >> celsius;
// calculate conversion factor for Celsius
// to Fahrenheit
int factor;
factor = 212 - 32;
// use conversion factor to convert Celsius
// into Fahrenheit values
int fahrenheit;
fahrenheit = factor * celsius/100 + 32;
// output the results (followed by a NewLine)
cout << "Fahrenheit value is: ";
cout << fahrenheit << " F" << endl;
return 0;
}
If you absolutely must have the pause at the end, check out this thread.
http://www.dreamincode.net/forums/showtopic30581.htmNow, stdio.h and stdlib.h should not add any additional code, but other headers may do so.
To actually compare the results of the iostream implementation, here are some results with the slightly modified C++ version above, as well as a pure C version
Pure C Version
CODE
#include <stdio.h>
int main(void)
{
int celsius;
int fahrenheit;
printf("Enter the temperature in Celsius:");
scanf("%d", &celsius);
fahrenheit = (212 - 32) * celsius/100 + 32;
printf("Fahrenheit value is: %d F\n", fahrenheit);
return 0;
}
Results
CODE
Cygwin GCC Port
g ++ -Wall -Wextra -ansi -pedantic
C++ - 477,718 bytes
C - 9,524 bytes
g ++ -Wall -Wextra -ansi -pedantic -O2
C++ - 477,562 bytes
C - 9,012 bytes
The following compile with -mno-cygwin, which basically makes it MinGW
g ++ -Wall -Wextra -ansi -pedantic -mno-cygwin
C++ - 475,377 bytes
C - 12,410 bytes
g ++ -Wall -Wextra -ansi -pedantic -mno-cygwin -O2
C++ - 474,724 bytes
C - 12,410 bytes
MS Complier v 15 (Visual Studio 2008 Pro)
cl /W3 /EHsc
C++ - 146,432 bytes
C - 55,808 bytes
cl /W3 /EHsc /O2
C++ - 144,384 bytes
C - 55,808 bytes
Borland Compiler
bcc
C++ - 148,992 bytes
C - 66,048 bytes
So, in terms of file size, you can conclude that the GCC implementation of iostream is far more bloated then the MS or Borland version. I did check the files the GCC (with -mno-cgywin) and the MS version. Both of them only depended on standard Windows DLLs, yet the MS version still depended on fewer dlls (MS - Kernel32.dll GCC - Kernel32.dll and MSVCRT.dll). This basically just means that yes, the GCC implementation of iostream isn't that great.
If file size is important, you may want to switch to C.