views:

144

answers:

1

I created a static Qt library by using VS2005.

It created an extra file "test_global.h" besides expected ones(test.h and test.cpp).

test_global.h

#ifndef TEST_GLOBAL_H
#define TEST_GLOBAL_H

#include <Qt/qglobal.h>

#ifdef TEST_LIB
# define TEST_EXPORT Q_DECL_EXPORT
#else
# define TEST_EXPORT Q_DECL_IMPORT
#endif

#endif // TEST_GLOBAL_H

Why this file is generated, how I suppose to use it?

Thanks.

+2  A: 

You mark your class (or methods) as exported in your library headers:

class TEST_EXPORT TestClass {
    // ...
};

Then in your library pro file you add:

DEFINES += TEST_LIB

So during the dll compilation your class header will have "Q_DECL_EXPORT" macro which is Qt way to tell the linker "export this class/method", and when you use your dll in some application, the header will have "Q_DECL_IMPORT" macro.

For more information, check the Qt documentation.

chalup
1-)Do I need to put "TEST_EXPORT" in front of every Symbols, or is scope exist?2-)Do I need to put "TEST_EXPORT" in front of classes which is not used by client?
metdos
Ad.1. If you want to export every symbol in class, put TEST_EXPORT in front of class name. If you want to export only some symbols, don't put TEST_EXPORT in front of class, put TEST_EXPORT in front of every exported symbol instead. Ad.2. No.
chalup