C++ Error Messages

ALERT! NOTE: Mainly compilation errors, while using CINT (C++ ROOT Interpreter)

-- JuanCastillo - 28 Jul 2008

BASICALLY :When the compiler complains saying ... you need to check...

Before reading this guide please check first the solutions of the proffesionals wink

Adding to an TObjArray

 error: request for member ‘Add’ in ‘Hlist’, which is of non-class type ‘TObjArray*’

Non-proper inizialization.Check where and how are you creating your array.
See this thread : ROOT talk

Assignment of an array

   error: ISO C++ forbids assignment of arrays 

Instead of an array, use a pointer.
That is, from My_array[] go to *My_array wink


   ISO C++ forbids declaration of `ClassDef' with no type 

Add in *.h files:

   #include "TObject.h"

where ClassDef is defined. BTW:ClassDef is used by ROOT for accepting your class, if your're asking about big grin

Duplicated nested type

   CGGasDict.cpp:176: error: duplicate nested type `
   make: *** [Linux/CGGasDict.o] Error 1

Move the structure OUTSIDE the class where you're defining it.

Floating point exception

   ********   Break ************* floating point exception 

  • Divisions by 0
  • Inexact calculations
  • Invalid operations
  • Overflow/Underflow (buffer)

Function undeclared

   error: ... undeclared (first use this function) 

  • The function declaration (of course). In the *.h it's only the name (EX: myfunc) but in the *.cpp you should write it like Myclas::myfunc.
  • The inheritance. If you are using a function that is a member of another member object, you need to include the header of the class and forward declaring it if you want the compiler to find the function.

GetMyClass segmentation violation

*** Break *** segmentation violation
 Generating stack trace...
 0xffffe420 in <unknown function>
 0x402afdf5 in TClass::GetMyClass(void const*) const ...

RUN-time fatal error.
ROOT is not finding your class "MyClass". Probably you are using an external class defined in another library.
I recommend you to wrap it: create a local class, fill it with the relevant information, include it in the local dictionary and link definition and compile again all. I found this problem while filling a tree.

Linking options

   g++: cannot specify -o with -c or -S and multiple compilations  *** Error 1. 

You will always get this error if there is a path missing a -I or -L, you have a -I or -L with no associated path, or you repeat -I or -L options. Check the makefile.

Linker input file unused

    gcc: -lpthread: linker input file unused because linking not done. 

Try to move some debug options (for example the -lpthread) at the makefile.
Put it at the end, or add it to the dict generator...

Link Requested for Unknown Class

   Error: link requested for unknown class MyClass MyLinkDef.h:15:
   Warning: Error occurred during reading source files
   Warning: Error occurred during dictionary source generation
   !!!Removing MyDict.cpp MyDict.h !!!
   Error: rootcint: error loading headers...

  • Naming. Maybe a typo in #ifndef preprocessor directives? (capital/noncapital, for example?)
  • Forward declarations of MyClass. Are they in every place where the class is needed?

ALERT!*NOTE:* This could make you obtain another error:

   MyDict.cpp:1617: error: no matching function for call to `
   GenerateInitInstanceLocal(const MyClass*)'

ROOT is taking care of your classes, and it is responsible of all the members you have.
So please try with another member structure.
Maybe you can simplify it? dead!

Non Aggregate type

   error: request for member `Something' in `
   this->MyClass::MyObject', which is of non-aggregate type `MyClass*'
   make: *** [Linux/MyClass.o] Error 1

Check how you're calling to the member `Something' of the class MyClass.
Probably you are calling it as a pointer having an object or viceversa.

Passing 'const' as 'this' discards qualifiers

   error: passing `const ...' as `this' argument of ...` discards qualifiers

Simply change the qualifier of your variable, don't use it as const. Example: map and const_iterator


     MyClass.h:6: error: redefinition of `class OtherClass'
     MyClass.h:6: error: previous definition of `class OtherClass'

Organize the header loading using precompiler commands. See CppCompilation for more details.

No Size indication

   Error ** Datamember... : no size indication. 
   Error ** Datamember... : pointer to fundamental type (need manual intervention)

This error you obtain if you declare a TObject derived class with an array member.
CINT is confused when you do that.

Add after member definition //!

      Int_t *member; //!    

No such file or directory

For includes, when compiling with a makefile.
Try to change the includes, for example, instead of

   #include <iostream.h>


   #include <iostream>

(remove .h)

Operator '@' or '**' negative operand

C++ error .

The FORTRAN operator ation"x**y" should be replaced by TMath::Power(x,y).

Source: here

Root Config: command not found

   make: root-config: Command not found 

You're not adding properly ROOT libraries.
Try to add the libraries using something like:

   $(shell root-config --glibs). 

Or simply check if you can run root (maybe not) roll eyes (sarcastic)


         In file included from MyClass.h:22,
                          from MyClass.cpp:10:
         MyOtherClass.h:127: error: `MyClass' was not declared in this scope

This problem I had whe I was trying to use MyClass in MyOtherClass, AND at the same time, MyOtherClass in MyClass.
You can force the recognition of MyClass forward declaring it in MyOtherClass AND viceversa.

Segmentation violation

   *********** Break ************* Segmentation Violation 

Memory problems. Check:
  • Storage (if infinite, you have a problem)
  • Pointers (bad defined, pointing inproperly)
  • Array sizes (maybe you are overfilling one array?)

Shared libraries

   error while loading shared libs: libSomething.so cannot open shared object file. No such file or directory /path/  

In the prompt write


Check that the path is there. If not, in the prompt write

   >export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/of/my/lib/

ALERT! NOTE: "/path/of/my/lib/" must point DIRECTLY to the folder where "libSomething.so" is. Don't skip "Linux" or this things. Now do "echo" again to check that the path is there. If you want to add more than one lib, separe the paths with ":" (semicolons). If export doesn't work, check your default shell and try the equivalent shell command. EX:

   > echo $SHELL
   >setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:/path/of/my/lib/

The system will now look for the libraries ALSO in the path you entered (I suppose that you have some paths already defined, as you saw after writting echo)

Symbol not defined

   Error: Symbol... is not defined in current scope 

Hide the file where the symbol is defined to CINT. You can do it like this:

      #if !defined(__CINT__)
      #include <types.h>;

Another version of the error is:

   Error: Symbol null is not defined in current scope  :0:

While compiling a class, you need to implement a default constructor or ROOT will not accept it.

Template members and Dictionary generation

    Linux/MyLib.so: undefined reference to `MyTemplateClass<int>::MyTemplateClass[in-charge]()'
    Linux/MyLib.so: undefined reference to `MyTemplateClass<double>::MyTemplateClass[in-charge]()'
    collect2: ld returned 1 exit status

Look for Template Support at the release notes.
If you want to avoid class definition (I think you should wink ) for this example, the header should be something like:

   template <typename T> class MyTemplateClass{
         T  fTemplateMember;
         MyTemplateClass();  //constructor

And the Link Definition if you want to use your class with a fTemplateMember int and double.

       #pragma link C++ class MyTemplateClass<int>+;
       #pragma link C++ class MyTemplateClass<double>+;

Because of that, in the code you must also write 2 constructors (default in this example) in this way:


ALERT! NOTE: If you write a destructor in the header, even a default one, you need also to write one destructor per each "use" of your class. To write the same code is not fair, don't you think so? >:-) So avoid it.

BTW, dont try to be smart and write in the code:

      template <typename T>

It will not work if you're generating a dictionary, and you will obtain the above error.

Type specifier ommited

   error: type specifier ommited for parameter 

Check arguments of functions.
Probably you are not passing the proper number of them or the proper argument.

Undefined reference (1)

   my_path/my_lib.so: undefined reference to `Ext_class::Ext_class[in-charge]()'

This error appears when an external library has not been properly linked in your makefile.
When you want to add your own class to ROOT (defining it as derived from TObject), you need to generate:
  • 1. A dictionary.
  • 2. A library.
Once you have them (in this order), you need to link all.
You can do it for your own application or you can use the features already included in an already compiled external library.
Being libExt_lib.so the external libary you want to link, and (EXT_DIR) the path of the library, your makefile should have something like:

  EXT_LIB       = -L$(EXT_DIR)/Linux -lExt_lib    

Sometimes the error is not so complicated. If the output s:

   Collect2: ld returned (number) exit status. Undefined reference to...

  • Functions & arguments given to the functions
  • Makefile
Clean and recompile all

Undefined reference (2)

       Linux/my_lib.so: undefined reference to `OneClass::ShowMembers(TMemberInspector&, char*)'
       Linux/my_lib.so: undefined reference to `ROOT::GenerateInitInstance(OneClass const*)'
       Linux/my_lib.so: undefined reference to `OneClass::Streamer(TBuffer&)'
       Linux/my_lib.so: undefined reference to `OneClass::Class()'

Check "OneClass": probably it is inheriting from TObject, so, you need to create not ONLY a library but also a dictionary.

Undefined reference (3)

.//Linux/my_ext_lib.so: undefined reference to `TVersionCheck::TVersionCheck[in-charge](int)'
..//Linux/my_ext_lib.so: undefined reference to `G__get_linked_tagnum_fwd'

You're trying to compile the new code (the one linking my_ext_lib.so) with another ROOT version that the one that was used for compiling my_ext_lib.so. Find out the ROOT version used for compiling it and compile your code with the same, or recompile my_ext_lib.so with the ROOT you're currently using.

Variable Size arrays forbidden

   Class.cpp:130: error: ISO C++ forbids variable-size array `BadArray'
   make: *** [Linux/Class.o] Error 1

Change the array definition. Instead of double BadArray[dinamicsize] write:

   double *BadArray; //pointer
   BadArray = new double[dinamicsize];

Vector error.

   error: 'vector' is used as a type, but is not defined as a type 

Check the includes and the classes. If not, write using namespace std; before ! You solve the problem also with writting instead of vector, std::vector. This error appears while using STL vectors, deques, lists, etc inside classes.

Virtual table error.

   undefined reference to virtual table. 

Non-inline non-abstract member function was declared within a class but NOT defined. Check defined functions. Maybe you delete one in one file but you call it or name it in another? 'grep' the function.
Topic revision: r8 - 2010-01-20, JuanCastillo
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding GSI Wiki? Send feedback
Imprint (in German)
Privacy Policy (in German)