Reputation: 11
I have a Qt+cmake project in Win10. The project structure is
Class1 and Class2 are both child classes of QObject. MainWindow, as an executable, includes both Class1 and Class2. Class2 includes Class1. However, the compiler alerts:
mocs_compilation.cpp.obj:-1: error: LNK2019: unresolved external symbol "public: static struct QMetaObject const Class1::staticMetaObject" ...
Class2.cpp.obj:-1: error: LNK2001: unresolved external symbol "public: static struct QMetaObject const Class1::staticMetaObject" ...
I have done:
#if defined(DLL_DECL)
#define DLL_DECL_SPEC Q_DECL_EXPORT
#else
# define DLL_DECL_SPEC Q_DECL_IMPORT
#endif
class DLL_DECL_SPEC Class1: public QObject
{
Q_OBJECT
...
}
I have tried:
#include "Class1.h"
in cpp of Class2. The error still remains...Do you have any idea about these errors? In Qt, is one QObject class only allowed to be used once? Is there any way to work around?
Thanks for any suggestions!
Upvotes: 0
Views: 517
Reputation: 11
As CristiFati mentioned, I create one ModuleXX.h for each dynamic library.
#if defined(DLL_DECLXX)
#define DLLXX_DECL_SPEC Q_DECL_EXPORT
#else
# define DLLXX_DECL_SPEC Q_DECL_IMPORT
#endif
In CMakeLists.txt, I rename the definitions as add_definitions(-DDLL_DECLXX)
. Now the include problem has been solved.
Upvotes: 1