When the subprograms are in the same file as the main program, use the compilation procedure described in the tip sheet "Compiling and Executing a Stand-alone Program" .
f77 [main] [sub1] [sub2] .. [subN] -o [output filename]where
f77 main.f one.f two.f func.f -o main.exeTo execute the program, type
main.exe
main.o one.o two.o func.o main.exeThe ".o" files are the relocatable binaries, which cannot be used separately, but must be linked together to create an executable file. The f77 command performs this step by calling the link editor and producing the executable file "main.exe".
Alternatively, you can compile each subprogram separately, producing individual ".o" files. Use the -c compiler switch to produce each ".o" file. For example,
f77 -c main.f f77 -c one.f f77 -c two.f f77 -c func.fThe final step is to link them together to make the executable file "main.exe".
f77 main.o one.o two.o func.o -o main.exe
Specify the full filename for the library in the compile statement. For example,
f77 main.f ~/mylib/mysubs -o main.exeor
f77 main.f one.f two.f func.f ~/mylib/mysubs -o main.exe
Use the "-L" option to specify the location of the library in the compile statement. For example,
f77 main.f -o main.exe -L$HOME/mylib -lmysubsor
f77 main.f one.f two.f func.f -L$HOME/mylib -lmysubsEven though the full filename is "libmysubs.a", only type the "mysubs" part with the "-l" option.
~consult/proto/xsetupIf you have defined your own aliases or environment variables, you will need to copy them into the new "dotfiles". Instructions are available on U-Discover!.
Compile your program by typing
f77 main.f -o main.exe -lmysubsor
f77 main.f one.f two.f func.f -lmysubs
For example, suppose the library file is named "libmysubs.a" and is stored in ~/mylib ($HOME/mylib). First, add the following line to the .localenv file described in alternative 3:
setenv LD_LIBRARY_PATH $HOME/mylib:$LD_LIBRARY_PATHThen compile your program by typing
f77 main.f -o main.exe -lmysubs
******************************************************************* * * * Correspondence to VS FORTRAN * * * ******************************************************************* * * * VS FORTRAN UNIX * * ========== ==== * * * * Compile, Load & Execute * * ======================= * * * * fortvs2 main f77 main.f * * fortvs2 sub f77 sub.f * * load main sub (start f77 main.o sub.o -o main.exe * * main.exe * * * * or * * * * f77 main.f sub.f -o main.exe * * main.exe * * * * * * Accessing User Created Library Routines * * ======================================= * * * * global txtlib vsf2fort mysubs * * fortvs2 main f77 main.f mylib/libmysubs.a -o main.exe * * load main (start main.exe * * * * or * * * * f77 main.f -o main.exe -L$HOME/mylib -lmysubs * * main.exe * * * * where the subprograms in the library * * libmysubs.a are located in the * * directory named $HOME/mylib. * * * * (See text for alternative methods) * * * *******************************************************************