Qt5 unresolved external function staticMetaObject

I have a class that is derived from QObject

and QRunnable

and also has a macro Q_OBJECT

. The library that contains the compiled classes is fine and I get the file .lib

and .dll

. I am using MSVC 2013 and QT 5.4 (precompiled binaries from qt.io).

Looking at the DLL using Dependency Walker I can see the function is there. The file gets moc'ed, which means I can look at the resulting CPP file. As proof, here is the function causing the problem.

const QMetaObject DHImageConvHandler::staticMetaObject = {
    { &QObject::staticMetaObject, qt_meta_stringdata_DHImageConvHandler.data,
      qt_meta_data_DHImageConvHandler,  qt_static_metacall, Q_NULLPTR, Q_NULLPTR}
};

      

Now when I try to create an application that links to this library I get the following error.

unresolved external symbol "public: static struct QMetaObject const DHImageConvHandler::staticMetaObject" (?staticMetaObject@DHImageConvHandler@@2UQMetaObject@@B) 
referenced in function "public: static class QString __cdecl DHImageConvHandler::tr(char const *,char const *,int)" (?tr@DHImageConvHandler@@SA?AVQString@@PBD0H@Z)

      

Changing the project type for a library from "Shared Library" to "Static Library" makes this go away, but I'm curious why. The code is in lib. I opened the import library with a text editor and searched staticMetaObject

, and as mentioned earlier, Dependency Walker also shows it's there.

Can anyone shed some light on this?

edit 01/10/2015 I made a reservation about who is using this library. This lib is linked with another library which is then part of the application.

+3


source to share


1 answer


Thanks Archie for pointing me in the right direction. The dllimport / dllexport prefixes are part of the code - wait for it - but every library uses the same macro and preprocessor directive. This means that when my problematic library is being used by another library's code, and both use the same macro to export their symbols, the second library includes the headers of the first library with dllexport instead of dllimport. As soon as I gave my lib problem, its own dllexport / dllimport macro worked.



+3


source







All Articles