These annoying errors have been haunting me the last couple of days, so I figured I should share the most common reason for their occurrence. That is in my projects at least.
This error is caused because the linker in gcc is unable to find the functions you have defined in your headers in your actual code. So if you have a header which looks like this:
#ifndef MESH_H #define MESH_H class Mesh { public: Mesh(); ~Mesh(); virtual void draw(); }; #endif // MESH_H
You must at least have these functions defined in your .cpp file:
#include "mesh.h" Mesh::Mesh() { } Mesh::~Mesh() { } void Mesh::draw() { }
After this, make sure you clean your compile environment to make sure no object files are being misinterpreted by the compiler. If you are using Qt or a project with a Makefile, you could just run these three commands (the first only applies to Qt projects).
qmake make clean make


Hi Svenn,
Nice of you for sharing your knowlage!
But your tips didn’t help in my case.
I get the error message “undefined reference to `vtable for …”
although the .h and .cpp files are synchronized and checked.
I’ve also cleaned the environment.
Have you any other tips?
Hi Teymoor,
vtable errors are sometimes tricky to figure out. I would double check the following:
1. All methods in your classes are both defined in the headers (.h) and the source files (.cpp)
2. All methods have matching parameters
3. The number of methods are the same
4. If you have inherited classes, make sure that all virtual functions are implemented (this shouldn’t lead to vtable errors, but is worth checking)
5. Check that all used libraries are included and check that you are also linking their dependencies.
6. Try to compile your project with only a few test files, but link and use the libraries you need. A vtable error could mean that a library that is referenced is missing some of its dependencies or that these dependencies are not linked properly.
7. Start from the bottom and build up everything again piece by piece, if possible. This way you can try find the problem in your code.
If you can’t figure it out, see if you can create a simple example that reproduces the error and post it here. Maybe I or someone else that stumbles over this post knows what to do.
Good luck!