If you do not find and explanation of an error that you have encountered listed here (and you compiled your program using gcc on babe.cs.um.edu.mt or a Linux box), please mail me the error/warning and I'll add it to this list.
Error messages and warnings are preceeded by the program file name and function in which the error was encountered. For example,
prog.c: In function `main':
indicates that the error was encountered in the program file prog.c, and specifically in function main. The next lines indicate the errors/warnings that occur in that function and program file. If the program is multi-function and/or multi-file, then each different function/file containing errors will be listed separately.
The warning/error lines following the function/program file identification line is a record of the program file containing the error; the line number in the source file at which the error occured; the string "warning", if the message is just a warning (nothing is printed if it is an error); and a description of the problem encountered. For example,
prog.c:3: warning: unknown escape sequence `\z'
indicates that a problem was encountered at line 3 of the program file prog.c. The message is just a warning. The problem encountered is that the character `\z' is not a known escape sequence. If there are no other errors, you will be able to run the program, but it will probably produce results which are different from what you wanted.
'variable' undeclared (first use in this function)
C is a typed language, which means that you must declare variables before
you can use them. C is also case-sensitive, so that var and
Var are considered to be different variables. You have either
forgotten to declare a variable before using it, or else you have mistyped
a variable name.
This is an error message - the compiler has had to stop compiling your program. This error message is usually accompanied by (Each undeclared identifier is reported only once for each function it appears in.). The same undeclared variable may occur several times in the same function, but the compiler reports only the first occurrance.
unknown escape sequence `\z'
An escape sequence is a character preceded by a '\'. The presence of the
'\' changes the function of the character following it. For example,
'n' is the character n, but '\n' is the newline
(return) character. Some characters, for example, z, do not
represent an escape sequence. The program will compile anyway (unless
there are other errors), because this is just a warning. However, it is
likely to produce results which are different from what you expect.
No such file or directory
You have asked the gcc compiler to compile a file which does not exist.
The gcc compiler expects C program files to have a .c file
extension. If you have a program file proc.c, you must use
gcc prog.c. Using gcc prog will result in the generation
of this error. This error is usually accompanied by No input files.
ld: elf error: file prog:
You will usually get the following message as well...
unknown type, unable to process using elf(3E) libraries
ld: fatal: File processing errors. No output written to a.out
collect2: ld returned 1 exit status
A nasty error, but one which is easily fixed! You have a C program stored in the file prog, but because you have not used the .c file extension, gcc cannot tell what type of program code is contained in the program file! To fix this error, simply rename prog to prog.c.
parse error before `string'
The C compiler has encountered something that it doesn't recognise, and it
cannot figure out what it might be. C statements usually start with a
reserved word, a variable name, or a function name. This error is normally
generated when the first word of a statement is unrecognised, and it cannot
possibly be a function call, variable name,
etc. e.g.,
main() { silly printf("Hello, world\n"); }
Alternatively, something, perhaps a close bracket ()) or a close brace (}), is missing at or around the indiciated line, before the character or string indicated by token. You may also have a surplus of brackets! You may also have a semi-colon (;) missing to terminate the previous statement.
Undefined first referenced symbol in file main /usr/local/lib/gcc-lib/sparc-sun-solaris2.7/2.95.2/crt1.o ld: fatal: Symbol referencing errors. No output written to a.out collect2: ld returned 1 exit status
Gcc has encountered what looks like a function call, but there is no function with that name. The name of the "missing" function is the first word of line 3 of the error message (main).
All C programs must have a function called main, because the execution of C programs starts from this function.
character constant too long
In C, strings must be surrounded by double quotation marks (""). If you
have used single quotation marks (''), then C expects to find a single
character (or an escape character).
warning: passing arg n of `function' makes
pointer from integer without a cast
You have called the function function. Argument n
is expected to be a pointer (we will learn about pointers in Lecture 6), but you have passed an integer instead. A type cast
explicitly changes the type of data from one type to another (Lecture 3), but you haven't used one. C is a typed
language, so you have to declare data types of variables and the type of
data that will be received by functions before you are allowed to use them.
This warning message is received whenever there is a type mismatch between
the data you pass to a function and the type of data that the function
expects. Although gcc will generate object code, this warning message
should not be ignored, because it usually indicates a logical error.
unterminated string or character constant
You have an unbalanced number of single or double quotation marks.
parse error at end of input
You probably have a missing close brace (}) somewhere in your
program. C cannot tell where it is missing from, so happy hunting!