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
}
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"
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.