CompilersThe default compiler command for any Unix system is "cc". On some systems, this is the actual name of the compiler installed on the system, but on other systems, Linux in particular, cc is just a link to another compiler. The problem here is that not all compilers work alike. For the purposes of this tutorial, we will use the GNU Project's free compiler, GCC. GCC is the default compiler for Linux systems, and most systems administrators will install it on other versions of unix. The command to call the compiler is "gcc" for C programs, g++ for C++ programs, and g77 for fortran programs. (For Bayou users, the proper C++ compiler is cxx.) Say we have a simple "hello world" program called hello.c. We type:
$ gcc hello.c
to compile the program. The executable produced by this is "a.out" in the current directory. This is the default name for executables. This could cause a problem if you were to compile more than one program in each directory, so our first gcc option will be for setting the output name to something better. In Unix, executables typically do not have extensions (like .exe, .com, or .bat). Following standard conventions, we will call our hello world program "hello".
$ gcc hello.c -o hello
Interestingly enough, this command matches the default rule for the make program which will be outlined later. Thus, you could also type:
$ make hello
cc hello.c -o hello The only problem here, is that the makefile uses "cc" instead of "gcc", so it is possible that your code may behave differently between various versions of Unix. The man page for gcc is quite extensive, so there are a few useful flags we'll point out here
|