Common compilation errors

From OTBWiki
Revision as of 04:00, 30 July 2009 by Christop (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This page is intended to describe common compilation errors encountered by developers as well as their possible causes. You may also want to have a look at runtime errors.

Constructor of class Foo is protected.

Foo instantiation is handled by smart pointers and you are trying to instantiate it without the object factory. Consider replacing

Foo myFoo;

by

Foo::Pointer myFoo = Foo::New();


error: expected initializer before ‘<’ token

You probably forgot to put the #include corresponding to the class you are trying to use. Check the line and add the corresponding

#include "otbNameOfTheClass.h" 

on top of the file.


error: no matching function for call to ‘otb::[...]’ [...] note: candidates are: void otb::[...]

This is a template error, you are probably trying to pass an object with a type which is not correct for the filter. For example, if you template your filter on otb::Image<unsigned int, 2> and you are trying to give it a otb::Image<unsigned char, 2> in the SetInput() method. Check your template type based on the hints given by the compiler.

error: undefined reference to MyClass::MyMethod()

You declared the method MyMethod() in MyClass header, but did not implement it in MyClass body (cxx file if not template, txx file otherwise).


error: passing ‘const MyObject’ as ‘this’ argument of ‘MyMethod()’ discards qualifiers

You are probably trying use a non const method on a const object. If this method is not declare as

MyMethod() const;

you can't guarantee the constness of the object. If MyMethod() does not modify members of the class, it should be declared as const.


‘FORWARD’ was not declared in this scope

Some enum are defined within the otb namespace. Most classes are defined in the namespace, and it is possible to use directly the enum name. However, when working outside of the namespace (particularly when writing the tests), the namespace need to be specified: use otb::FORWARD instead.


undefined reference to ‘typeinfo for otb::YourNewClass’

If you've just defined YourNewClass as a non template classe, chances are that you need to launch a cmake in the directory to add the new class to the makefile.


error: ‘class otb::UnaryFunctorObjectListFilter<otb::ObjectList<otb::Polygon<double> >, otb::ObjectList<otb::Polygon<double> >, otb::SimplifyPathFunctor<itk::SmartPointer<otb::Polygon<double> >, itk::SmartPointer<otb::Polygon<double> > > >’ has no member named ‘SetTolerance’

This is due to a change in the API since OTB 2.8: you have to replace

 filter->SetTolerance(2);

by

 filter->GetFunctor().SetTolerance(2);