undefined reference to `vtable

Jul 7, 2015 at 2:12am
Hello,
I am begginner in C++ and using 3rd party library.
When running make target on Xubuntu I get the following error:

[100%] Building CXX object CMakeFiles/step-22.dir/step-22.cc.o
Linking CXX executable step-22
CMakeFiles/step-22.dir/step-22.cc.o: In function `LeftChannelBoundaryValues':
/media/sf_Eclipse_Deal_II_sharedFolder/Eclipse_Win_workspace/ChannelFlowWithFlatPlateSource/src/LeftChannelBoundaryValues.h:19: undefined reference to `vtable for LeftChannelBoundaryValues'
CMakeFiles/step-22.dir/step-22.cc.o: In function `~LeftChannelBoundaryValues':
/media/sf_Eclipse_Deal_II_sharedFolder/Eclipse_Win_workspace/ChannelFlowWithFlatPlateSource/src/LeftChannelBoundaryValues.h:16: undefined reference to `vtable for LeftChannelBoundaryValues'
/media/sf_Eclipse_Deal_II_sharedFolder/Eclipse_Win_workspace/ChannelFlowWithFlatPlateSource/src/LeftChannelBoundaryValues.h:16: undefined reference to `vtable for LeftChannelBoundaryValues'
collect2: error: ld returned 1 exit status
make[6]: *** [step-22] Error 1
....

Here is the code of LeftChannelBoundaryValues.h:
#ifndef SRC_LEFTCHANNELBOUNDARYVALUES_H_
#define SRC_LEFTCHANNELBOUNDARYVALUES_H_

#include <deal.II/base/function.h>
using namespace dealii;

class LeftChannelBoundaryValues : public Function<2>
{
public:
LeftChannelBoundaryValues () : Function<2>(3) {}
virtual double value (const Point<2> &p, const unsigned int component = 0) const;
virtual void vector_value (const Point<2> &p, Vector<double> &value) const;
};

#endif /* SRC_LEFTCHANNELBOUNDARYVALUES_H_ */

and code of LeftChannelBoundaryValues.cpp:
#include "LeftChannelBoundaryValues.h"

LeftChannelBoundaryValues::LeftChannelBoundaryValues() {
// TODO Auto-generated constructor stub

}

LeftChannelBoundaryValues::~LeftChannelBoundaryValues() {
// TODO Auto-generated destructor stub
}

void LeftChannelBoundaryValues::vector_value (const Point<dim> &p,
Vector<double> &values) const
{
values(0) = 1; //u1=1
values(1) = 0; //u2=0
}

What could be the reason of this error?
Thank you.
Jul 7, 2015 at 7:10am
1
2
3
4
5
6
7
8
LeftChannelBoundaryValues::LeftChannelBoundaryValues() {
// TODO Auto-generated constructor stub

}

LeftChannelBoundaryValues::~LeftChannelBoundaryValues() {
// TODO Auto-generated destructor stub
}
THose two functions are not actualy declared in class definition. Constructor one is actually tries to redefine already defined constructor.
Jul 10, 2015 at 5:01am
I removed the above costructors it helped. Thank you!
Jul 12, 2015 at 9:04am
The same error has appeared again even though I did not change niether LeftChannelBoundaryValues.h nor LeftChannelBoundaryValues.cpp. I did change the code that uses these files, but its pretty big to include it here. Could somebody explain the logic behind this error message so that I could trubleshoot it?
The only related change is that I moved the line

#include "LeftChannelBoundaryValues.h"

from beginning of all includes to after all includes.

[100%] Building CXX object CMakeFiles/step-22.dir/step-22.cc.o
Linking CXX executable step-22
CMakeFiles/step-22.dir/step-22.cc.o: In function `LeftChannelBoundaryValues':
/media/sf_Eclipse_Deal_II_sharedFolder/Eclipse_Win_workspace/ChannelFlowWithFlatPlateSource/src/LeftChannelBoundaryValues.h:18: undefined reference to `vtable for LeftChannelBoundaryValues'
CMakeFiles/step-22.dir/step-22.cc.o: In function `~LeftChannelBoundaryValues':
/media/sf_Eclipse_Deal_II_sharedFolder/Eclipse_Win_workspace/ChannelFlowWithFlatPlateSource/src/LeftChannelBoundaryValues.h:15: undefined reference to `vtable for LeftChannelBoundaryValues'
/media/sf_Eclipse_Deal_II_sharedFolder/Eclipse_Win_workspace/ChannelFlowWithFlatPlateSource/src/LeftChannelBoundaryValues.h:15: undefined reference to `vtable for LeftChannelBoundaryValues'
collect2: error: ld returned 1 exit status
make[6]: *** [step-22] Error 1

=====================
Just in case current versions of LeftChannelBoundaryValues.h:
#ifndef SRC_LEFTCHANNELBOUNDARYVALUES_H_
#define SRC_LEFTCHANNELBOUNDARYVALUES_H_

#include <deal.II/base/function.h>

using namespace dealii;

class LeftChannelBoundaryValues : public Function<2>
{
public:
LeftChannelBoundaryValues () : Function<2>(3) {}
virtual double value (const Point<2> &p, const unsigned int component = 0) const;
virtual void vector_value (const Point<2> &p, Vector<double> &value) const;
};

#endif /* SRC_LEFTCHANNELBOUNDARYVALUES_H_ */

and LeftChannelBoundaryValues.cpp
#include "LeftChannelBoundaryValues.h"

double LeftChannelBoundaryValues::value (const Point<dim> &p,
const unsigned int /*component*/) const
{
return p.square();
}


void LeftChannelBoundaryValues::vector_value (const Point<dim> &p,
Vector<double> &values) const
{
values(0) = 1; //u1=1
values(1) = 0; //u2=0
}
Jul 12, 2015 at 9:13am
Does Fucnction class templace have pure virtual destructor? Or any pure virtual functions?
Jul 13, 2015 at 1:56am
I am not sure how to determine this. Its code and all relevant classes is here:
https://www.dealii.org/8.2.1/doxygen/deal.II/function_8h_source.html

is this pure virtual destructor?
virtual ~Function () = 0;
Last edited on Jul 13, 2015 at 1:58am
Jul 13, 2015 at 7:01am
is this pure virtual destructor?
Yes. And every class deriving from Function have to overload it or nothing will work.
Jul 13, 2015 at 8:43am
Should my destructor also be virtual or doesn't matter?
Jul 13, 2015 at 8:53am
Your destructor will be virtual. If you made something virtual, there is no way to make it not virtual. presence of virtual keyword in derived classes is only for convenience.
Jul 15, 2015 at 12:45am
got you, thank you!
Topic archived. No new replies allowed.