Q_DECL_EXPORT keyword meaning

后端 未结 2 1905
故里飘歌
故里飘歌 2021-02-18 21:25

Q_DECL_EXPORT int main(int argc, char **argv)

What does this Q_DECL_EXPORT before int main(...) means?

2条回答
  •  无人及你
    2021-02-18 22:13

    Excerpt from QT docs:

    Depending on your target platform, Qt provides special macros that contain the necessary definitions:

    • Q_DECL_EXPORT must be added to the declarations of symbols used when compiling a shared library.
    • Q_DECL_IMPORT must be added to the declarations of symbols used when compiling a client that uses the shared library.

    I haven't check the QT code, but most likely this macro will do following:

    #ifdef _WIN32 || _WIN64
        #define Q_DECL_EXPORT __declspec(dllexport)
        #define Q_DECL_IMPORT __declspec(dllimport)
    #else
        #define Q_DECL_EXPORT
        #define Q_DECL_IMPORT
    #endif
    

    __declspec(dllimport) and __declspec(dllexport) tells the linker to import and export (respectively) a symbol from or to a DLL. This is Windows specific.

    In your particular case this macro probably could be removed, since main() most likely is not part of a library.

提交回复
热议问题