Q_decl_export must be added to the declarations of symbols used when compiling a shared library 一个 共享库导出给用户使用的类、符号、函数等都需要用宏Q_DECL_EXPORT来定义导出,一个 使用共享库的应用程序需要通过Q_DECL_IMPORT导入共享库里的可用对象。 Q_decl_import must be added to the declarations of symbols used when compiling a client that uses the shared library.
See also q_decl_export and creating shared libraries If we don’t want things to be visible for the outside world (on windows), we simply don’t use export_api. It is usually used with libraries to define those functions which need to be exported from the library, in order to be imported (used) by other libraries or by executables.
为了在客户端使用共享库,一些平台可能需要一个特殊的导入声明。 为此,Qt 提供了两个特殊的宏: Q_DECL_EXPORT:当编译共享库时,必须将其添加到使用的符号声明。 Q_DECL_IMPORT:当编译一个(使用了该共享库)客户端时,必须将其添加到使用的符号声明。 Q_decl_export is a macro that expands to either the msvc or mingw specific attribute to let you write portable code, so you should use it Similarly, if you're using qmake, you can add config += hide_symbols in your pro file to add the toolchain specific linker flags to hide symbols by default. 文章讲述了Qt框架中的Q_DECL_IMPORT和Q_DECL_EXPORT宏在处理动态链接库中的符号导入和导出,如何根据不同构建方式正确管理类和函数的可见性及链接问题。
When you write dlls, you have to explicitly mark objects (functions, classes or variables) that should be visible from the outside and you do this with __declspec (dllexport) tag All other objects won't be accessible from the outside and only dll code will be able to use them. Now i've been wondering, as normally the q_decl_export macro has to be put in front of every class/function that should be exported from the shared library, what about inline functions fully defined in a public header file, to be used by the user, like q_declare_operators_for_flags does? With this solution we can now export freely everything we want to from liba and link from liba’s dll