Compiling in GNU cygwin

To: cv -|- home -|- index -|- unix1 -|- automake -|- end

Single Source Application:

I have created a folder called, testap, and in that folder, a directory src. Note I use either the word 'folder', or 'directory', to mean the same thing! So my cygwin GNU prompt will be -
~/testap/src $

Note the prompt is of the form, username, at machine name. Below I shall just use a generic -
~/testap/src $

First I create the source file, in this case testap.cxx. This is the source listing of the file created, between the comments '//' -
// testap.cxx
#include <stdio.h>
int main( int argc, char * argv[] ) {
   printf( "Test application ...\n" );
   return 0;
}
// eof - testap.cxx

Compiling, and linking could not be simpler ... assuming the single source is testap.cxx, the command is -
$ gcc testap.cxx
If there are no errors in the source, an application 'a.exe' will be created. Since a.exe is very generic, you may want to give the application a more appropriate name, say testap - use the command -
$ gcc testap.cxx -o testap
The '-o testap' tells the compiler we want the application output as testap. In the GUN-WIN32 this will become 'testap.exe', and can be run by the simple command -
$ ./testap

The command show all items in this folder, and their PERMISSIONS -
~/testap/src
$ ls -all
total nn
drwxrwxrwx+ 2 username None 0 Nov 18 14:19 .
drwxrwxrwx+ 5 username None 0 Nov 18 12:49 ..
-rwxrwxrwx 1 username None 165 Nov 18 12:26 testap.cxx
-rwxr-xr-x 1 username None 8836 Nov 18 14:18 testap.exe

~/testap/src

In some environments, the compiler may NOT have given the correct permissions, to enable you to run the application. Traditional unix systems use 3 kinds of entities to which they grant (or deny) access: The user which owns the file, the group which owns the file, and everybody else. Each of these entities may be given access to read the file ('r'), write to the file ('w') and execute the file ('x'). Fixing the permission, so you, the user, can run the file, try the command -
$ chmod u+rwx testap.exe

This 'testap.exe' does not contain any debug information, except some function names, and all this information can be stripped from the file by the command -
$ strip testap.exe
After this is done, note the change, the reduction in the file size, by the command -
$ ls testap.exe -all
-rwxr-xr-x 1 username None 3072 Nov 18 15:02 testap.exe

top

checked by tidy  Valid HTML 4.01 Transitional