c++ - Error: LNK2001: unresolved external symbol "private: static class -
this forum contains many examples of such situation, in case static variables defined correctly, still error. issue not duplicate of previous , above link not answer question. suggested 21 answers post not have solution simon gave me here, please unmark "duplicate".
seems i've declared correctly, check this:
.h file:
class valuesetsmodelscontainer : public qobject { q_object public: static void dllexport loadallergiesvaluesets(mptdatabase *db); static void dllexport loadproceduresvaluesets(mptdatabase *db); // models access functions static qstandarditemmodel *drugsmodel(); static qstandarditemmodel *substancemodel(); static qstandarditemmodel *reactionsmodel(); private: static qstandarditemmodel *mydrugsmodel, *mysubstancemodel, *myreactionsmodel; };
.cpp:
qstandarditemmodel *valuesetsmodelscontainer::mydrugsmodel = 0; qstandarditemmodel *valuesetsmodelscontainer::mysubstancemodel = 0; qstandarditemmodel *valuesetsmodelscontainer::myreactionsmodel = 0; qstandarditemmodel *valuesetsmodelscontainer::drugsmodel() { return valuesetsmodelscontainer::mydrugsmodel; } qstandarditemmodel *valuesetsmodelscontainer::substancemodel() { return valuesetsmodelscontainer::mysubstancemodel; } qstandarditemmodel *valuesetsmodelscontainer::reactionsmodel() { return valuesetsmodelscontainer::myreactionsmodel; }
so static variables defined in cpp, still linking error in module calls valuesetsmodelscontainer methods:
- allergiesdialog.obj:-1: error: lnk2001: unresolved external symbol "private: static class qstandarditemmodel * valuesetsmodelscontainer::mydrugsmodel" (?mydrugsmodel@valuesetsmodelscontainer@@0pavqstandarditemmodel@@a)
- allergiesdialog.obj:-1: error: lnk2001: unresolved external symbol "private: static class qstandarditemmodel *
valuesetsmodelscontainer::mysubstancemodel"
(?mysubstancemodel@valuesetsmodelscontainer@@0pavqstandarditemmodel@@a)- allergiesdialog.obj:-1: error: lnk2001: unresolved external symbol "private: static class qstandarditemmodel *
valuesetsmodelscontainer::myreactionsmodel"
(?myreactionsmodel@valuesetsmodelscontainer@@0pavqstandarditemmodel@@a)
where problem be?
from link commands turned out linking objects dll , in second step link dll final binary. might caused subdirs template in project settings.
whenever want have method of dll available outside, need make available via __declspec( dllexport ). guess done in custom precompiler constant dllexport
.
now try in .h file:
static dllexport qstandarditemmodel *drugsmodel(); static dllexport qstandarditemmodel *substancemodel(); static dllexport qstandarditemmodel *reactionsmodel();
to make methods available outside dll.
by way: don't think makes sense here have intermediate dynamic library (dll) if linking stuff own project , don't need make available else. consider using static library instead setting template = lib
, config += staticlib
in .pro
file valuesetsmodelscontainer in. topic , question.
Comments
Post a Comment