title: Why am I getting "undefined reference to vtable..." errors when linking this Qt 5.0 application?
body: <p>I've got a relatively simple Qt 5.0 project that uses CMake 2.8.9:</p>
  
  <p>CMakeLists.txt:</p>
  
  <pre><code>cmake_minimum_required(VERSION 2.8.9)
  set(CMAKE_INCLUDE_CURRENT_DIR ON)
  project(hello-world)
  
  find_package(Qt5Widgets REQUIRED)
  qt5_wrap_ui(hello-world_UI MainWindow.ui)
  
  add_executable(hello-world MainWindow.cpp main.cpp ${hello-world_UI})
  qt5_use_modules(hello-world Widgets)
  </code></pre>
  
  <p>MainWindow.h:</p>
  
  <pre><code>#ifndef MAINWINDOW_H
  #define MAINWINDOW_H
  
  #include &lt;QMainWindow&gt;
  
  namespace Ui {
      class MainWindow;
  }
  
  class MainWindow : public QMainWindow
  {
      Q_OBJECT
  
      public:
  
          MainWindow();
          virtual ~MainWindow();
  
      private:
  
          Ui::MainWindow * const ui;
  };
  
  #endif // CMAINWINDOW_H
  </code></pre>
  
  <p>MainWindow.cpp:</p>
  
  <pre><code>#include "MainWindow.h"
  #include "ui_MainWindow.h"
  
  MainWindow::MainWindow()
      : ui(new Ui::MainWindow)
  {
  }
  
  MainWindow::~MainWindow()
  {
      delete ui;
  }
  </code></pre>
  
  <p>main.cpp:</p>
  
  <pre><code>#include &lt;QApplication&gt;
  #include "MainWindow.h"
  
  int main(int argc, char * argv[])
  {
      QApplication app(argc, argv);
  
      MainWindow win;
      win.show();
  
      return app.exec();
  }
  </code></pre>
  
  <p>The project also includes a <code>.ui</code> file created with Qt Creator 2.6.1 (MainWindow.ui).</p>
  
  <p>When I attempt to build the file with <code>g++</code> on Linux, I receive the following errors:</p>
  
  <pre>
  CMakeFiles/hello-world.dir/MainWindow.cpp.o: In function `MainWindow::MainWindow()':
  MainWindow.cpp:(.text+0x3b): undefined reference to `vtable for MainWindow'
  MainWindow.cpp:(.text+0x4d): undefined reference to `vtable for MainWindow'
  CMakeFiles/hello-world.dir/MainWindow.cpp.o: In function `MainWindow::~MainWindow()':
  MainWindow.cpp:(.text+0xaf): undefined reference to `vtable for MainWindow'
  MainWindow.cpp:(.text+0xc1): undefined reference to `vtable for MainWindow'
  collect2: error: ld returned 1 exit status
  </pre>
  
  <p>What could possibly be causing this sort of error? I recently switched to CMake from <code>qmake</code> and I never remember running into this much trouble getting a trivial example to compile. What am I doing wrong?</p>
  
  <hr>
  
  <p><strong>Edit:</strong> here is the command being used to link everything:</p>
  
  <pre>
  /usr/bin/c++ CMakeFiles/hello-world.dir/MainWindow.cpp.o
  CMakeFiles/hello-world.dir/main.cpp.o -o hello-world -rdynamic
  /usr/local/Qt-5.0.0/lib/libQt5Widgets.so.5.0.0
  /usr/local/Qt-5.0.0/lib/libQt5Gui.so.5.0.0
  /usr/local/Qt-5.0.0/lib/libQt5Core.so.5.0.0 
  -Wl,-rpath,/usr/local/Qt-5.0.0/lib
  </pre>