Resolve/C++ FAQ: Compile-Time Errors

This section explains likely causes and suggests corrections for errors that occur when you try to compile and link your program. If you have a particular error message that you can't understand, pick a word from it (not from the particular classes and operations of your program, but from the fixed part of the error message) and "Find" that word in this page.

This entire section assumes you know how to find the relevant error message in the first place! The C++ compiler we use is not known for emitting comprehensible error messages. Here is our best advice on that:

Finally, you should know that the "Build Project" command in emacs (equivalently, the "Compile" button in emacs or the command-line "rcpp-make") will compile all the .cpp files in the current directory. An error in any of them can cause trouble. We generally recommend that you have only one .cpp file in any directory.


General Error Categories

Error 1: Syntax errors in RESOLVE_Foundation or RESOLVE_Catalog code

Error 2: Compilation produces no executable file, file date is in the future, and other weirdness

Specific Error Messages

Error 3: "constructor is private within this context"

Error 4: "assignment operator is private within this context"

Error 5: "void value not ignored as it ought to be" or "could not convert '...operator=...' to 'bool'"

Error 6: "request for member 'Put_To' in ..., which is of non-class type `const char[...]'"

Error 7: "`XXX' undeclared (first use this function)"

Error 8: "`class XXX' used where a `int' was expected"

Error 9: "`class XXX' is from private base class within this context"

Error 10: "/bin/ld: Unsatisfied symbols"

Error 11: "no matching function for `operator [ ]'"

Error 12: "no match for `operator <'" (or >, or similar)

Error 13: internal compiler error


Error 1: Syntax errors in RESOLVE_Foundation or RESOLVE_Catalog code

Example 1: You get error messages which, when you find the first actual error in emacs (see above), take you into some RESOLVE_Foundation or RESOLVE_Catalog component.
Diagnosis 1:

Although it is theoretically possible that the maintainer of the RESOLVE_Foundation or RESOLVE_Catalog screwed up and left a syntax error in the code, it is much more likely that there is a syntax error -- almost certainly a missing closing brace, "}" -- somewhere in your main program file or in other code that you wrote. One way to find this problem is in emacs. Go to the last closing brace in your main program, delete it, and retype it. At the bottom of the emacs window you'll see a message saying which opening brace it matches. You expect it to match "program_body main () {". If it doesn't, then you're missing a closing brace somewhere in the middle, and you can use the same technique to narrow down the place where you need to add one.

A more cumbersome but, in some cases, perhaps necessary way to pinpoint such errors is to comment out as much of the program as possible, while making sure that the compile-time error still occurs. That way, one can delineate the part of the code with the syntax error. "Binary search" is occasionally needed: Comment out about half your code to see which half causes the problem, and keep narrowing it down by commenting out about half of the offending part. Notice that, of course, you have to leave uncommented pieces of code that have some hope of compiling! For example, you can't comment out exactly the first half of the code if that would leave the uncommented part beginning in the middle of a block; and you can't comment out declarations at the beginning of a block if the objects declared there are used in an uncommented part later in the block.


Error 2: Compilation produces no executable file, file date is in the future, and other weirdness

Example 2: Compilation is very fast, does not produce any error messages, and does not produce an executable file. Or you see a message appearing before the compilation command is invoked, stating that a file with .d extension has a date in the future.

Diagnosis 2:

Make sure that your main program file contains "program_body main ()", being sure that those parentheses ("()") are there. Once you are sure your saved file has "program_body main ()", follow the instructions given below for anything else weird happening during compilation. Ignore the "date in the future" error, which seems to be the result of different servers on the network having different ideas of what time it is. The program should compile just fine. If anything else weird happens during compilation, go to the UNIX prompt, change directory to the subdirectory with your program, and type:

rcpp-make clean
That should remove all the .d, .o, and executable files from your project directory, thus allowing you to perform a clean compile.

Error 3: "constructor is private within this context"

Example 3:

Queue_Test.cpp:26: constructor `Queue_Of_Text::Queue_Of_Text(const class Queue_Of_Text &)' is private within this context.

Diagnosis 3:

Most likely, this error message is caused by one of the following programmer errors:


Error 4: "assignment operator is private within this context"

Example 4:

Queue_Test.cpp:30: method `class Queue_Of_Text & Queue_Of_Text::operator =(const class Queue_Of_Text &)' is private within this context.

Diagnosis 4:

The programmer tried to use assignment on an object of a programmer-defined type, e.g.:

object Queue_Of_Text q1, q2;

//...

q1 = q2;
Most likely, the programmer either intended to use the swap operator &= and made a typo, or in fact intended to copy the value of q2 to q1, and then should have instead used:
q2.Copy_To (q1);
But note that operation Copy_To is not available for all types, e.g., it is not available for Queue_Of_Text in this example unless Queue_Of_Text is an instance of an extension of Queue_Kernel which provides Copy_To.


Error 5: "void value not ignored as it ought to be" or "could not convert '...operator=...' to 'bool'"

Example 5:

Queue_Test.cpp:36: void value not ignored as it ought to be

Queue_Test.cpp:36: could not convert '...operator=...' to 'bool'

Diagnosis 5:

The programmer probably typed "=" instead of "==" in a conditional expression, e.g.:

if (j = 3) ...
instead of
if (j == 3) ...
Note that in normal C++, this error does not cause compile-time problems; it just does weird things at run-time.


Error 6: "request for member 'Put_To' in ..., which is of non-class type `const char[...]'"

Example 6:

.../rcpp/RESOLVE_Foundation/Character_OStream/Character_OStream.h:
In function `class Character_OStream & operator <<(class Character_OStream &, char (&)[161])':
.../rcpp/RESOLVE_Foundation/Character_OStream/Character_OStream.h:72:
request for member `Put_To' in `t', which is of non-class type `const char[161]'

Diagnosis 6:

Resolve/C++ Character_OStream objects only support output of string literals no longer than 100 characters. The programmer tried to output a string literal longer than 100 characters, e.g.:

cout << "A very long string literal more than 100

         characters in length; in fact, in the case of the sample

         error message, something like 161 characters in length";
The literal should be broken into parts less than 100 characters long, and output in parts, e.g.:
cout << "A very long string literal more than 100"

     << " characters in length; in fact, in the case of the sample"

     << " error message, something like 161 characters in length";


Error 7: "`XXX' undeclared (first use this function)"

Example 7:

a.cpp:40: `Disrete_Log' undeclared (first use this function)
a.cpp:40: (Each undeclared identifier is reported only once for each function it appears in.)

Diagnosis 7:

An object, an operation, or a class is used that has not been declared. Either the programmer forgot to declare it, or more likely, the name is misspelled. Remember that upper and lower case are different!


Error 8: " `class XXX' used where a `int' was expected".

Example 8:

a.cpp: In function `int Calc_Square(class Integer)':
a.cpp:32: `class Integer' used where a `int' was expected

Code causing this error:

global_function Calc_Square (preserves Integer x)

{

    return x * x;

}
Diagnosis 8:

In C++, the default return type of an operation is int. In the example above, the programmer forgot to specify the return type of Calc_Square operation to be Integer, and the compiler assumed it should be int. But the code of the operation attempts to return an Integer object, and hence the compile-time error. The moral is that one should always remember to specify the return type.


Error 9: "`class XXX' is from private base class within this context"

Example 9:

/usr/class/sce/rcpp/RESOLVE_Catalog/CT/Queue/Kernel_1_Body.h:100: `class Integer Queue_Kernel_1,Queue_Kernel_1a_Rep >::Length()' is from private base class
Test.cpp:21: within this context

Diagnosis 9:
 

If you forget the keyword instantiates when instantiating a template, it will still compile, but you'll get this error message at the point where you try to call an operation from the concrete instance class you're creating. The error is not really in the RESOLVE_Catalog component; see the "context" where you're calling an operation from the erroneously-declared class, in this example line 21 of Test.cpp. The error is not actually on line 21, either; it's in the declaration of the concrete instance class whose operation is being called on line 21.


Error 10: "/bin/ld: Unsatisfied symbols"

Example 10:

collect2: ld returned 1 exit status /bin/ld: Unsatisfied symbols: f (code)

Diagnosis 10:

There are several possible explanations for this error, including:


Error 11: "no matching function for `operator [ ]'"

Example 11:

no matching function for call to `Record<Integer,Text,...>::operator [ ] (Integer)'

Diagnosis 11:

The most likely cause for this error is that you have violated the "redeclaration rule" by declaring an object with the same name as you have used in a Record field_name declaration. In this case the object you declared with the same name as some field is of type Integer, so the compiler is looking for a Record accessor which takes an Integer argument. To fix the problem, change the name of the Integer object so it is not the same as the name of a Record field.


Error 12: "no match for `operator <'" (or >, or similar)

Example 12:

no match for `operator >'(class Natural_Number_1_C_L, int)

Diagnosis 12:

Most likely, the code causing this error involves Natural numbers, as in this situation:

object Natural_Number_1_C_L n;

...

if (n > 0) {...}
Natural numbers (objects of type Natural_Number_1_C_L) do not have comparison operators defined for them; the same is true for most programmer-defined types. You must use the operation Compare to perform comparisons of Natural numbers. Furthermore, since Compare takes an object of type Natural_Number_1_C_L, and 0 is a constant of type Integer, you must do something like the following:
object Natural_Number_1_C_L zero;

zero.Convert_From_Integer (0); // not really needed, since it's initially 0!

if (n.Compare (zero) > 0) {...}
Note that the preferred way of comparing a Natural number to 0 is:
if (n.Discrete_Log () > 0) {...}

Error 13: internal compiler error

Example 13:

a long error message produced by the compiler that includes the words "internal compiler error" and gives instructions where to send a report regarding this error

Diagnosis 13:

This error is rare and hard to reproduce; hence, we don't yet have an exact transcript of the error message. In fact, we suspect it will no longer occur with recent compiler updates. If you encounter this or a similar-sounding error, please save the contents of your local catalog, and send it to Wayne Heym (heym@cse.ohio-state.edu); doing so will help us prepare better advice about this error.

We have been able to work around the few occurrences of this error by declaring an extra object within a sequence of declarations. Simply declaring an Integer object has worked for us. For example, the program causing the error may have contained the following declarations:

object Segment_Record seg_info;
object Array_Of_Source_Record source_list;
object Array_Of_Object_Code_Record object_code;
Inserting another declaration, like so:
object Segment_Record seg_info;

// The declaration of totally_superfluous_object helps the
// compiler avoid an internal error when proceeding to the
// compilation of the declaration of source_list.
object Integer totally_superfluous_object;
    
object Array_Of_Source_Record source_list;
object Array_Of_Object_Code_Record object_code;
caused this error to go away. Look for some indication of which instance of some template seems to be involved in the error as a guide to finding the troublesome declaration.
Bruce W. Weide <weide@cse.ohio-state.edu>

Last modified: Mon Aug 15 14:32:14 EDT 2011