Bad Magic
Number
The bad magic number error means that the file is incorrectly
named. The compiler relies on the filename to tell it what
type of file it is being given. If the file is not named
correctly the compiler does not know how to process the file.
C source files must be called something.c. Fortran
source files must be called something.f. Pascal
files must be called something.p. Use the mv command
to rename the file. See the man page on the compiler in
question for a full list of file naming conventions that it
supports.
Linking with the
Math Library
Library files contain the compiled code for functions a
program uses but does not implement. For example, in C, you
use the existing "cos" function to find the cosine; you don't
write your own function to do this. Most of the time these
functions are included in default libraries that the compiler
links into your executable for you. One noteable exception
though is the math library.
The Unix C compiler does not automatically link to the math
library. C users who wish to use functions in the math.h
header file must compile their programs with the -lm option.
The -l is for link. The m is name of the math library. For
example, if a C program in a file called mathtest.c used the
math library, it would have to be compiled with the command:
cc mathtest.c -o mathtest -lm
Library files are kept in /lib in a file named
libx.a where x is the name of the library
you specify in the -l option. The -lm option includes the
library named /lib/libm.a. If a user were compiling a program
for the Ingres system they would need to use -lsql to include
/usr/libsql.a.
Undefined Symbol
Error
Undefined symbol errors occur when the linker can't find the
definition for a name it encountered in your program. Usually
the name is a function and the user forgot to include the
library file or the object file that defines the function. If
you were using the cos function in a C program and didn't
compile it with -lm you would expect cos to be an undefined
symbol when the linker tried to make the final executable
file. (See above for more info.) The same thing would be true
if a user was trying to compile a program that used the
Ingres database system and didn't include the appropriate
Ingres libraries.
The problem may also be that the user never defined the
function or misspelled the function when they defined or used
it. In the case of a language like C++ that allows two
functions to have the same name but different parameter
lists, the problem may be that user is not calling the
function with the proper types of variables.
Segmentation
Fault Errors in Compiled Programs
Segmentation fault, in English, means a program has been
terminated by the operating system because it tried to access
memory it is not allowed to access. This is usually the
result of problems with pointers in the user's program.
Users are responsible for debugging their own logic problems.
OIT staff helping users debug logic
problems in a class assignment can be construed as Academic
Dishonesty.
Users can help themselves debug logic problems by learning
how to use the debuggers on the system.
In the case of a segmentation fault, the easiest thing one
can do is to compile the program with debugging information
and then run it under the debugger. It will still
segmentation fault, but you can find out where if it was
running under the debugger. In the case of the GNU gdb
debugger, the "where" command shows the stack frames and the
stack frames tell you what statement was being executed when
the problem occurred. This is usually a dead giveaway to the
real problem.
Strange Error Messages After a Program Has Compiled
There are cases when a compiler might produce an unusual
error such as:
mips-tfile:Symbol table is not last
symbol table ends at 0, .o ends at 122880
The problem is usually that the user exceeded their quota
when the final executable file was being generated so only
part of the file got written. The user should reduce their
disk space usage and try compiling the program again. For
classroom accounts the user should get rid of any .o files
and executables from previous assignments. Another option is
to remove the -g option from the compiler. This option
includes debugging information in the file and consequently
makes the executable file much larger. If the user has copied
large files from their professor's account into their own,
they can reduce their disk usage by deleting their private
copy and using them directly from the other account.
|