Compiling and running your program
In the following examples I'll use the C-compiler (cc). If you want to use Fortran, just use your favorite Fortran compiler; it will work in the same way.
Let's assume you just created a file "helloworld.c" with your favorite editor, then
cc helloworld.c
will first compile your program to an object file; cc will then implicitly call the loader (ld) to link with routines of the standard library (if needed) and produce an executable file named "a.out". To run that program, just type
./a.out
It depends on your shell's search path whether you need the leading ./ or not. If the search path contains the current directory ("."), you won't need it; if not (which is more secure) you have to tell the shell to look for "a.out" in the current directory.
If you have several source files you may use
cc -o myprog source1.c source2.c -lm
This will compile both source files, link them with routines from the math library "/usr/lib/libm.a" as told by the -lm option and produce an output file "myprog" (the -o option). You might also do this in steps:
cc -c source1.c
cc -c source2.c
cc -o myprog source1.o source2.o -lm
The -c option means "compile only", and will result in ".o"-files; both objects are linked in the third step.
If you want to build your own libraries from object files, use the ar command.
If you have large projects, you should use the make command. For the example above you would create a file named Makefile in the directory where your sources reside. The file should contain something like
myprog: source1.o source2.o
cc -o myprog source1.o source2.o -lm
source1.o: source1.c
cc -c source1.c
source2.o: source2.c
cc -c source2.c
Then you just type make to have your program built.
The lines starting in column one specify "targets" and the files they depend upon. The lines starting with a tab-character specify "rules" for producing the targets (note: the lines must start with a tab, not with a series of blanks). Make will compare the dates of the target files and the "dependency" files and rebuild the targets only if necessary. This is very useful if you have lots of source files.
"make" can do a lot more, but that's beyond the scope of this primer.
[The above Makefile example contains more then actually needed because make knows a lot "intrinsic rules" - it's just there for clarity.]
If your program doesn't do what it was supposed to do, use a debugger (dbx or cdbx on the Crays). If you compiled your program with the -g option you are able to debug at source level.
If things go really wrong a core file is written to your current directory when your program dies. You can also use a debugger to do post-mortem analysis with the core file.
Previous: Editors
