• Undefined first referenced symbol in file main /usr/local/lib/.../crt1.o ld:

  • fatal: Symbol referencing errors...
     
      This is a link time error. Fixing these errors is very straightforward. The
      error message is telling you that you have declared a method or free function
      in your .h file, but you have not created a definition for the method or free function.
      The definition is usually in the .cc or .cpp file.  The names of the symbols that are
      the cause of the problem are given in a list:

       symbol                                                                            in file
       __ls__FR7ostreamRC6String                               /var/tmp/cca001BP1.o
      cout                                                                                 /var/tmp/cca001BP1.o
      __cl__6Stringii                                                          /var/tmp/cca001BP1.o
      length__C6String                                                      /var/tmp/cca001BP1.o
      __ls__7ostreamPFR7ostream_R7ostream       /var/tmp/cca001BP1.o

      The symbols that are causing the problem are on the left. The list of files on
      right are not really useful to you.

      You will notice that the names of the missing symbols have been mangled to
      where you do not recognize the names. To demangle the names you can use
      the 'c++filt' command. for example:
       

        the mangled name:  length__C6String

        is demangled into:  String::length(void) const

        %   c++filt length__C6String


      So now you can tell that the undefined symbol is the method length that is a
      member of the String class.

      Now that you know what the symbol is, here are few things to try in order to fix the problem:
       

      1. Verify that you have a definition of your method or function in the .cc or .cpp

      2. file. If there is not one, and you don't plan on writing one at this time then
        just create an "empty definition".

        empty definition of a method called Search in the class ListClass that has an
        int return type:

          int ListClass::Search() {   }
        empty definition of  a function called FindMax with an int return type, and
        one parameter:
          int FindMax(ListClass AListofNums) {   }
        The {   } is what makes this an empty definition. Later, when you are
        ready, you can add the real code to the method or function.
         
      3. Check the spelling and especially the CAPITALIZATION of the method

      4. or function in both the declaration and the definition.
         
      5. Make sure that the 'g++' command you are typing in contains the

      6. .cc or .cpp file in the list of files.  If you are using a 'Makefile', then
        you should check there for this information.
    Back to Error List
     
  • Somefile:#: parse error before 'some symbols'

  •  
      The 'some symbols' can be any string. Sometimes its just a single character like
      the ';' or an identifier. In either case, the problem is that there is something
      illegally typed on line # and the problem appears right before the 'some symbols'.

      This can be something misspelled, something that has not be properly declared
      (See  #Somefile:#: warning: ANSI C++ forbids declaration 'SomeIdentifi  or
       #Somefile:#: 'SomeIdentifier' undeclared (first use this functio ), something
      could be typed in the wrong order.

      There are various things that can be wrong here, but for the most part it should
      be a problem that is local to that line #.

    Back to Error List
     
  • Somefile:#: warning: ANSI C++ forbids declaration 'SomeIdentifier' with no

  • type or storage class
     
      The words 'storage class' usually throw students off when they are trying to fix
      this error. The words 'storage class' is just another way of saying 'data type'.
      This is a warning, but it is usually followed by an error( #Somefile:#: 'SomeIdentifier' undeclared (first use this functio ). The # is the line number where the faulty
      declaration takes place.

      Typically this error appears when you trying to declare an identifier to be
      a type of one of your classes, and the compiler is not aware of your class name
      when it encounters the identifier.

      Here are some suggestions for fixing this problem:
       

      1. Verify that the type your are using to declare this identifier is spelled

      2. correctly and is correctly CAPITALIZED.
         
      3. Make sure the proper .h file has been #included in this Somefile file.
    Back to Error List
     
  • Somefile:#: 'SomeIdentifier' undeclared (first use this function)

  • Somefile:#: (each undelcared identifier is reported only once Somefile:#:
    for each function it appears in.)
     
      This looks like two different error messages, but they aren't. The first line is
      telling you that you have some variable name or function name in your
      program that you have not declared yet. The second line is just telling you
      that this name may be used in multiple places, but the compiler is only
      going to report it once.

      This error could result from this error #Somefile:#: warning: ANSI C++ forbids declaration 'SomeIdentifi , just fix the preceding error and the problem will most
      likely go away. Another possibility is that you simply forgot to declare the variable or function, and just put add the declaration to the appropriate part of the file Somefile.
      Finally there is a really tricky possibility. This is where the identifier is actually a data member of a class. In this case, check the declaration for the function in which this problem pops up in: you are looking for mispellings, the fact that the function definition is a free function definition vs a member function definition(remember only member functions can see private class members).
       

    Back to Error List
     
  • Somefile:#: type specifier omitted for parameter Somefile.cc: In method

  • 'YourClass::TheMethod(...)'
     
      This error message is a very easy one to fix. If you have a method that is a
      member of the class 'YourClass', and this method has a parameter X of type
      int then the header of the method should look like the following:
       
        void YourClass::TheMethod(int X)
      The 'int' is the type specifier. So if you get the error message your code
      probably looks like this:
       
        void YourClass::TheMethod(X)
      This error can be in either the declaration of the method or function or the
      definition of the method or function.
    Back to Error List
       


      The following group of messages all begin with:
        In file included from somefile.cc:#: somefile.h:#:
      all of this stuff basically means that the file that is giving you problems was #included
      in the file somefile.h which was #included in the file somefile.cc.(sometimes this is
      useful information)
         
  • Somefile: #: warning: implicit declaration of function 'SomeFunction'
    •  
      To understand this message, you need to understand what the word implicit
      means. The word is the opposite to explicit. An explicit declaration would be
      where the function has been explicitly declared as a free function prototype or
      a member function prototype in the class declaration. To solve this problem:
       
      1. Determine if the function is a class member or free function
      2. Check the spelling of the class member and the function all where the

      3. error occurred. (Change the spelling to the one that will save the most time).


      There are more complex situations where you are using multiple .cc files and .h
      files in your program. And if everything is spelled properly, then you may want
      to look at #includes and make sure you are including the .h file where the
      declaration should be explicitly done.


     Back to Error List

  • ... missingfile.h: No such file or directory
      The meaning of the error is self-explanatory, but fixing it is not always
      always straightforward. The meaning is obviously that the compiler
      can not find the file missingfile.h.

      There are a plethora of things that could be wrong:
       

      1. The filename is misspelled or CAPITALIZED wrong in the #include

      2. statement which is located in somefile.h.
      1. The #include is using <...> instead of "..." or vice-versa.

      2.  
      3. If the #include is properly using the "..." then the file may not be in

      4. your current directory. Use the ls command to check.
    Back to Error List
         
  • ... culprit.h:X: redefinition of 'some program structure'

  •     culprit.h:Y: previous definition here
     
      This is a complex way of saying that on line X of the culprit file there is definition
      of a some identifer(could be a function/method name  or variable name).
      And on line Y there is the original definition.

      Most of the time, either line X or Y is a #include statement, and that is where
      you will find the other definition.
       

    Back to Error List
       
  • ... firstfile.h:#: conflicting types for `typedef  OldType NewType'

  •     secondfile.h: previous declaration as 'typedef AnothaOldType NewType'
     
      This error is related to the redefinition error ( #... culprit.h:X: redefinition of 'some program structure' ). This is where you have two typedef statements.  Both of
      the typedef statements create the same NewType from different old types. So
      basically, if OldType and NewType are the same thing, and AnothaOldType and
      OldType are different then AnothaOldType and NewType can not be the same.

      Simply stated:

      if (OldType == NewType) && (AnothaOldType != OldType) then
          it follows that AnothaOldType != NewType.

      An example:

      SortedListClass.h:9: conflicting types for `typedef struct listNode * ptrType'
      StackP.h:10: previous declaration as `typedef struct stackNode * ptrType'

      Notice how both the pointers struct listNode and structstackNode are being
      called ptrType. This is not legal.


    Back to Error List