Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Linker error "undefined reference to `typeinfo for QMainWindowLayout'" when compiling on Linux
Uwe Kindler last edited by
I face a strange linker error when compiling a Qt apllication on Linux with Qt 5.2.0 (also happens with Qt 5.1.1) that uses private Qt header qmainwindowlayout_p. I created a small test application to demonstrate this error. You can download it here:
Simply unpack the archive, cd into the folder PrivateTest and the type _qmake PrivateTest.pro _and make all. The test application consists of a small shared library that contains my custom MainWindow class derived from QMainWindow. Inside of this class I use functionality of the private class QMainWindowLayout. The shared library compiles fine without any errors. My small application uses the main window class from this shared library for its main window and therefore links to the shared library.
When linking the application, the linker produces the following error:
./libmainwindowex.so: undefined reference to `typeinfo for QMainWindowLayout'
The test project compiles perfectly fine on a Windows machine with Qt 5.2.0 and MinGW (GCC 4.8.0) but fails to compile on a Ubuntu 12.04 machine. If I remove the code in my MainWindowEx constructor, then the applicarion compiles fine. If I change the line
@QMainWindowLayout* Layout = dynamic_cast<QMainWindowLayout*>(layout());@
@QMainWindowLayout* Layout = qobject_cast<QMainWindowLayout*>(layout());@
The error changes to
./libmainwindowex.so: undefined reference to `QMainWindowLayout::staticMetaObject'
Is there any Linux profi out there, that knows why this error occures and why the project compiles fine on a windows machine. Is use the default Qt 5.2.0 version from the installer with GCC 4.8.1. It looks like the linker is not pulling in the QMainWindowLayout related stuff into the shared library. But I don't know why.