Debugging the Program:
Compilation and Syntax Errors


Now you are ready to compile and debug the program.
 
  • Select the "Build Project" option from the "Resolve/C++" menu. 
  • Notice that the command line

  • Compile command: /class/sce/rcpp/tools/rcpp-make
    appears in the mini-buffer at the bottom of the XEmacs window. Press Enter.

    This is the command that creates your executable files. When you select this, it will compile and link all of the .cpp files in your current directory which need to be recompiled. Normally, a file with a ".cpp" extension is the source code for an executable Resolve/C++ program.

    Notice that a new buffer is automatically created in your XEmacs window as shown in the next figure. The buffer is titled *compilation* and is used to show the status of the compiler and linker, as well as the error messages.

    Also note that when the cursor is in the *compilation* buffer the "Resolve/C++" menu is replaced by a menu titled "Compile." This menu contains different commands that you may use while your program is being compiled. For example, sometimes you may want to stop the compilation process because you see an error and want to correct it immediately. You can use the "Kill Compilation" option within the "Compile" menu for that purpose.
     
  • After compilation is completed click on the "Resolve/C++" menu and then choose the "First Error" option. 
  • The first compilation error message appears at the top of the *compilation* buffer, while the cursor is positioned at the beginning of the line where the error was detected in the Euclid.cpp buffer.

    Your first error message should be the following, or something very similar:

               Euclid.cpp:96: error: `If' undeclared (first use this function)
    This error means that "If" is not recognized by the compiler as a word (that is to say, a symbol) that has been prevously declared. Do you know what's wrong? The "I" in the keyword if is capitalized. C++ is case-sensitive, so "If" is not the same as "if".
     
  • Change the case of the "I" in the if-statement.
  • Rebuild (recompile) the program by repeating the same method you used the first time. Re-read the directions if you forget exactly how to do it. You may see a mini-buffer message asking if you want to save the file. This happens whenever the file has been changed and not saved before doing the "Build Project" command. Respond by pressing y.
  • Your new error message (remember to use "First Error") should indicate that the compiler expected a semicolon (';') before the } that follows the statement
    small &= large.

    Note that small &= large is not followed by a semicolon (;). Every statement in C++ has to be terminated by a semicolon.
     
  • Position the cursor right after the large in the small &= large statement and add the necessary semicolon.
  • Should you rebuild the project at this point, as above, or try to correct more errors? Generally, if you have a simple syntax error message like this one and it's not followed by a long list of other error messages, it might be worth correcting more errors before recompiling. However, as a general rule, the only error you can really count on being an actual error is the first one. Sometimes all the other errors are the result of the C++ compiler trying to recover from the first error and picking the wrong way to recover, so it then thinks lots of other things that follow are also errors. Nonetheless, let's push ahead this time...
  • Select "Next Error" from the "Resolve/C++" menu. 
  • The new error message will appear at the top of the *compilation* buffer, and the cursor will be positioned at the appropriate line in the program. The error message indicates that the compiler expected a right (that is to say, closing) parenthesis before the { which follows the if. (Despite the fairly high quality of the error messages we've seen so far, sometimes the compiler cannot detect exactly what the problem is, and will just indicate the presence of an error somewhere before the point when it detected the error.)

    Can you guess what the precise problem is? The number of left parentheses in the if-condition ((small < 0) or (large <= 0) is not the same as the number of right parentheses. Specifically, there is a right parenthesis missing.
     
  • Position the cursor after the fragment (large <= 0) and add the missing parenthesis. 
  • As it turns out, insertion of this right parenthesis has solved our earlier problem of the statement we inserted being indented too far by the Tab key. Now the Tab key will indent this line properly.
     
  • Position the cursor anywhere on the line at the end of the file that contains the statement output.Close_External (); and tap the Tab key. This action has aligned this statement properly with the one above it.


  •  
    Previous Table of Contents Continue


    Last modified: Wed Apr 2 09:39:56 EDT 2008