Personal tools
You are here: Home Developer Resources Knowledgebase When creating a library with Qt/Windows and using it in an application, then there is a link error regarding symbols which are in the library
Document Actions

When creating a library with Qt/Windows and using it in an application, then there is a link error regarding symbols which are in the library

 


Answer:

When seeing errors like the following:

 MyObj.obj : error LNK2019: unresolved external symbol
 "public: static struct QMetaObject const MyObj::staticMetaObject"
 (?staticMetaObject@MyObj@@2UQMetaObject@@B) referenced in function
 "class MyObj * __cdecl qobject_cast<class MyObj *>(class
 QObject *)"

 

it is probably a result of the linker not finding the symbols from the library.  You need to make sure that the symbols in your library are properly exported when the library is created.  Subsequently imported when you are linking against the library, so you should have something like the following in a header file in your library:
 

#if defined TEST
#define TEST_COMMON_DLLSPEC __declspec(dllexport)
#else
#define TEST_COMMON_DLLSPEC __declspec(dllimport)
#endif

 

and use it in the classes that you wish to make available to the application like:

class TEST_COMMON_DLLSPEC MyObj : public QObject
{
...
};

 

Then add to your library's .pro file the following line so it knows that the symbols need to be exported in this case:

 DEFINES += TEST

 

 

 

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: