c – Q_DECL_EXPORT关键字的意思

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

在int main(…)之前,这个Q_DECL_EXPORT是什么意思?

摘自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.

我没有检查QT代码,但很可能这个宏将执行以下操作:

#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)和__declspec(dllexport)告诉链接器将元素(或分别)导入和导出到DLL中).这是Windows特定的.

在您的特定情况下,这个宏可能会被删除,因为main()很可能不是库的一部分.

翻译自:https://stackoverflow.com/questions/13911387/q-decl-export-keyword-meaning

转载注明原文:c – Q_DECL_EXPORT关键字的意思