Debugging the Program:
Linker Errors



 
  • Save the modified Euclid.cpp buffer into the file ~/euclid/Euclid.cpp by clicking on the "Save" icon, or by using the "Save Euclid.cpp" option from the File menu, or by pressing Ctrl-x Ctrl-s
  • Select the "Build Project" option from the "Resolve/C++" menu again. 
  • You will see the following error message near the bottom of the *compilation* buffer:

    Undefined                       first referenced
     symbol                             in file
    Greatest_Common_Divisor(Integer, Integer)Euclid.o
    Here a linking error was detected. In case of linking errors, the linker cannot specify the line number in your program where the error was detected. The most common type of linker error, "undefined symbol", occurs when you are calling a function whose body is not defined.

    Examine the comment that specifies the requires and ensures clauses of the Greatest_Common_Divisor function. The comment is not terminated by */. The compiler thought that everything up to the */ at the end of the function body was part of the comment. But the compiler did not detect this error!  The linker detected the error, and produced an error message indicating that it has failed to find the body of the function.
     
  • Correct the error by typing */ immediately after the ! that follows the ensures clause of the Greatest_Common_Divisor function (line 57). You'll have to manually reindent this line after you finish.
  • Notice that XEmacs thinks the function body is still in a comment. This is because it uses only local information and updates the highlighting only locally when you make a change.  If you save the buffer (using the "Save" icon) then, from the File menu, select "Revert Buffer Euclid.cpp" followed by clicking "Yes" to confirm your choice, the code will be rehighlighted from the beginning.  Good, the function body no longer seems to be inside a comment!

  • Now that you have corrected the error, you are ready to recompile the program. 

  • Select the "Build Project" option once more. 
  • The compiler and linker will display some messages indicating their status, and finally you will see the message:

         ==== All executables rebuilt ====
    This indicates that there are no more compiler or linker errors in your program.



     
    Previous Table of Contents Continue


    Last modified: Fri Dec 15 16:15:02 EST 2006