-

Bourne Shell: Chapter 5b

-

Please contact or Mt Xia for assistance with all your shell programming needs.


  • 5. COMPILING PROGRAMS IN UNIX. Go to the bottom, first,previous,next, last section, table of contents.

    5.11 FORTRAN: Giving a Name to the Output File

    It is possible to have the output sent to a file you specify instead of the default, a.out, by using the following command:
      
      Command Format:  f77 -o output source                        
                                                                   
      output - the name of the executable file                     
                                                                  
      source - the name of the Fortran source code file            
    
    The -o option tells the f77 utility to tell the link editor to use the specified name for the output instead of the default a.out. NOTE: It is not necessary for the -o option to appear after the f77 command. The filename that appears after the - o is the name of the output file. For example, f77 source -o output is the same as f77 -o output source. Sample Session: $f77 -o hello hello.f $hello Hello from main! Calling function1! Hello from function1! Back from function1! Calling function2! Hello from function2! Back from function2! That's all! $

    5.12 FORTRAN: Producing an Assembly Listing

    This option causes f77 to compile Fortran programs and leave the corresponding assembly language source programs in a file with filename extensions of .s.
     
      Command Format:  f77 -S hello.f                              
                                                                   
      -S = Compile only                                            
    
    Sample Session: $f77 -S hello.f $ls -C example.f hello hex.c octal.c hello.c hello.s multiply.c $ The file hello.s contains the assembly listing.

    5.13 FORTRAN: Main and Two Subroutines in Three Separate Source Files

    Sample Session: $cat main.f program calling write(6,100) 100 format (' Hello from main!',/) write(6,110) 110 format(' Calling subroutine1!',/) call sub1 write(6,120) 120 format(t15' Back from subroutine1!',/) write(6,130) 130 format(' Calling subroutine2!',/) call sub2 write(6,140) 140 format(t15' Back from subroutine2!',/) write(6,150) 150 format(' That's all, folks!') end $cat sub1.f subroutine sub1 write(6,200) 200 format(t20,' Hello from subroutine1!',/) end $cat sub2.f subroutine sub2 write(6,210) 210 format(t20,' Hello from subroutine2!',/) end

    5.14 FORTRAN: Compiling But Not Producing an Executable Module

    Using the above program, the following command will compile but not produce an executable module.
     
      Command Format:  f77 -c main.f sub1.f sub2.f                 
                                                                   
      -c = Compile, but do not load object files.  This option     
           causes f77 to compile and/or assemble source code       
           programs and leave the corresponding object programs    
           in files with filename extensions of .o.                
    
    Sample Session: $f77 -c main.f sub1.f sub2.f main.f: MAIN: calling: sub1.f: sub1: sub2.f: sub2: $ls a.out *.o a.out not found funct1.o funct2.o hello.o main.o sub1.o sub2.o $ The -c options causes the compilation system to suppress the link edit phase. This produces an object file or files, in this example (main.o sub1.o sub2.o), that can be link edited at a later time with the f77 command with no options. 5.15 FORTRAN: Compiling Object Files to Produce an Executable Module The command to produce an executable nodule from several object files is done in the following manner:
      
      Command Format:  f77 obj_1 obj_2 obj_3                       
                                                                  
      obj_1 through obj_n - the object files                       
    
    Sample Session: $f77 main.o sub1.o sub2.o $ls -C funct1.o funct2.o hello.o main.o sub1.o sub2.o a.out $

    5.16 COBOL: Sample Program with a Main and Two Subroutines

    Sample Session: $cat teacher.cob identification division. program-id. teacher. environment division. configuration section. data division. working-storage section. procedure division. begin section. begin-it. display " Hello from main!". display " Calling subroutine1!". perform subroutine1. display " Back from subroutine1!". display " Calling subroutine2!". perform subroutine2. display " Back from subroutine2!". display " That's all, folks!". stop run. subroutine1 section. sub1. display " Hello from subroutine1!". subroutine2 section. sub2. display " Hello from subroutine2!".

    5.17 COBOL: Compiling a Program

     
      Command Format:  cobol source_filename                       
    
    Three files are created by the compiler. They are identified by the same filename as the source code but with a different extension. They have the extensions .IDY, .INT, and .LST. NOTE: The extensions are uppercase characters. UNIX is case sensitive. Sample Session: $cobol teacher.cob $ls teacher* teacher.IDY teacher.INT teacher.LST teacher.cob $

    5.18 COBOL: Running a Program

    $cbrun teacher.INT Hello from Main! Calling subroutine1! Hello from subroutine1! Back from subroutine1! Calling subroutine2! Hello from subroutine2! Back from subroutine2! That's all, folks! $

    Workshop 5

    This workshop will reinforce your understanding of the ideas presented in Chapter 5. Login to the Multimax using the username and password given to you by the instructor. Each student is to complete the entire workshop. DESK EXERCISES 1. "C": What is the command to compile, assemble, and load source code programs? 2. "C": What is the filename extension that indicates a source code program? An assembly language program? An object code file? 3. "C": What is the default filename assigned to the executable file? 4. "C": What command can be used to rename the executable file produced by the cc compiler? What are the file protections associated with the executable? 5. "C": What option will produce an assembly listing? What is the filename extension of this file? Continue on the next page 6. "C": What command will compile the source code program but will not load object files but will keep the object files in files with extensions of .o? 7. FORTRAN: What is the command to invoke the compiler? 8. FORTRAN: What is the filename extension for source code programs? 9. FORTRAN: What is the name of the default executable file? 10. FORTRAN: How can you change the permissions on the executable module so anyone can execute it? 11. FORTRAN: What option on the call to the compiler will allow you to specify the name of the executable file? 12. FORTRAN: What option on the call to the compiler will produce an assembly listing? What is the filename extension of this file? 13. FORTRAN: What option will produce object modules but not produce an executable module? 14. FORTRAN: What command will produce an executable module from several object modules? 15. COBOL: What is the command to call the compiler? 16. COBOL: What are the three files created by the compiler? What are the filename extensions? 17. COBOL: Which of the three files that have been created are used to run the program? COMPUTER EXERCISES 18. Copy the following files from /user0/teacher: main.c funct1.c funct2.c Are these programs "C", FORTRAN, or COBOL? Compile these three files creating an executable file called main1.exe and then execute it. What are the file protections? Why? 19. Now append the three files into one file. Use output redirection. Compile the file creating the executable file called main2.exe . Execute main2.exe. 20. Copy the following files from /user0/teacher: main.f sub1.f sub2.f Compile these three files creating an executable file called main1.exe . Execute main1.exe 21. Now append the three files into one file. Compile the file creating the executable file called main2.exe . Execute main2.exe. 22. COBOL: Copy teacher.cob from /user0/teacher. Compile and run it.

    Go to the top, first,previous,next, last section, table of contents.