CopperSpice Overview  1.5.1
Shared Libraries

The following information pertains to Shared Libraries.

Using Symbols from Shared Libraries

Symbols (functions, variables or classes) contained in shared libraries intended to be used by applications or other libraries, must be marked as exported.

The unexported symbols should not be visible from outside the shared library. On most platforms, compilers will hide them by default. On some platforms a special compiler option may be required to hide these symbols.

Depending on your target platform, CopperSpice provides special macros which 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

The second step involves creating a special header. This header must be created for usage of a shared library from another application or another library. The purpose of this special header is to ensure the correct macro is invoked.

As an example, given a shared library called mySharedLib. A special header for this library, mysharedlib_global.h, might look like the following:

1 #include <QtGlobal>
2 
3 #if defined(BUILD_MYSHAREDLIB)
4 # define MYSHAREDLIB_EXPORT Q_DECL_EXPORT
5 #else
6 # define MYSHAREDLIB_EXPORT Q_DECL_IMPORT
7 #endif

In the Makefile.am used to build the shared library add the following to your CXXFLAGS.

-DBUILD_MYSHAREDLIB


In each header of the shared library specify the following:

#include "mysharedlib_global.h"
MYSHAREDLIB_EXPORT void someFunc();
class MYSHAREDLIB_EXPORT MyClass...