Qt World Summit: Submit your Presentation

MOC Linking Errors from MSVC 2015

  • I've been using cmake to generate a MSVC project file. The entire project is written in C++ and makes use of signals and slots. I've enabled the "AUTOMOC" option cmake provides and it generates the necessary "moc_filename.cpp" files. I've included the generated files at the bottom of each implementation file for each class. The project compiles, but fails on the linking step with these types of errors:

    windows_gui_automoc.obj : error LNK2005: "private: static void __cdecl RemoteWindow::qt_static_metacall(class QObject *,enum QMetaObject::Call,int,void * *)" (?qt_static_metacall@RemoteWindow@@CAXPEAVQObject@@W4Call@QMetaObject@@HPEAPEAX@Z) already defined in moc_RemoteWindow.obj
    moc_ServerTab.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const QWidget::staticMetaObject" (?staticMetaObject@QWidget@@2UQMetaObject@@B)
    TabDialog.obj : error LNK2001: unresolved external symbol "public: static struct QArrayData const * const QArrayData::shared_null" (?shared_null@QArrayData@@2QBU1@B)

    Any ideas as to what might be causing this?

  • Lifetime Qt Champion

    If you use automoc then you do not have to include the moc_.cpp files in your source files.
    The moc_
    .cpp files are compiled and linked automatically.

Log in to reply