CSM217: C for Computer Scientists

Common gcc Compiler Errors

This is a list of common gcc compiler errors and warnings, and their explanations. Please note that the errors are specifically for the Solaris (UNIX) operating system.

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.

List of errors

General Compile-time error/warning description
'variable' undeclared (first use in this function)
unknown escape sequence
No such file or directory
ld: elf error: file prog:
parse error before `string'
Undefined symbol
character constant too long
passing arg n of `function' makes data type from another data type without a cast
unterminated string or character constant
parse error at end of input

General Compile-time error/warning description

In C, a compilation error is ususally fatal, meaning that the C compiler cannot compile the source code. A warning, on the other had, is usually just that. The compiler has identified that there may be a problem, but it can produce object code anyway. Warnings should not be ignored, because they usually do indicate that there is something wrong with the program, and it is likely to behave differently from what you would expect.

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.

Back to top

'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.

Back to top

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.

Back to top

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.

Back to top

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.

Back to top

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.

Back to top

Undefined symbol

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.

Back to top

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).

Back to top

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.

Back to top

unterminated string or character constant

You have an unbalanced number of single or double quotation marks.

Back to top

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!

Back to top