Important: Please read the Qt Code of Conduct -

Linker error while accessing static member funtion of QString with /GZ compiler option

  • Hi,

    I am facing a problem when linking my project with /GZ compiler option.

    I followed below steps

    1. Created a shared library to include QtCore modules
    2. included QtCore in my cpp file and added QString test = QString::number(5000); to convert number into a QString.
    3. Then added the
      QMAKE_CFLAGS += /Gz
      into the .pro file
    4. Rebuild entire project

    There are linker errors for these QString.
    error LNK2019: unresolved external symbol "__declspec(dllimport) public: static class QString __stdcall QString::number(int,int)" (_imp?number@QString@@SG?AV1@HH@Z) referenced in function "void __stdcall function(void)" (?function@@YGXXZ)

    If I remove above compiler option /GZ from a .pro file it links successfully.
    My observation is accessing all static member functions of a class are giving linker error with this compiler option.
    For Example:
    quint64 g_ulCurrentPID = QCoreApplication::applicationPid();
    Also my project settings include "UNICODE" and "No (/Zc:wchar_t-)". I tried with "treat _wchar_t as default Built-in Type" as Yes. Still I am facing the same problem.

    Could you please help to solve this linker error

    Thanks & Regards,

  • Just guessing, but perhaps you should compile Qt itself with this option too for this to work?

Log in to reply