Creates initialization code for a bundle.

Each bundle which wants to register itself with the CppMicroServices library has to put a call to this macro in one of its source files. Further, the bundle’s source files must be compiled with the US_BUNDLE_NAME pre-processor definition set to a bundle-unique identifier.

Calling the CPPMICROSERVICES_INITIALIZE_BUNDLE macro will initialize the bundle for use with the CppMicroServices library.


If you are using CMake, consider using the provided CMake macro usFunctionGenerateBundleInit().



Initialize a static bundle.

This macro initializes the static bundle named _bundle_name.

  • _bundle_name: The name of the bundle to initialize.

If the bundle provides an activator, use the CPPMICROSERVICES_IMPORT_BUNDLE macro instead, to ensure that the activator is referenced and can be called. Do not forget to actually link the static bundle to the importing executable or shared library.



Import a static bundle.

This macro imports the static bundle named _bundle_name.

  • _bundle_name: The name of the bundle to import.

Inserting this macro into your application’s source code will allow you to make use of a static bundle. It will initialize the static bundle and reference its BundleActivator. If the bundle does not provide an activator, use the CPPMICROSERVICES_INITIALIZE_STATIC_BUNDLE macro instead. Do not forget to actually link the static bundle to the importing executable or shared library.


#include "cppmicroservices/BundleImport.h"




Export a bundle activator class.

Call this macro after the definition of your bundle activator to make it accessible by the CppMicroServices library.

  • _activator_type: The fully-qualified type-name of the bundle activator class.


class MyActivator : public BundleActivator


  void Start(BundleContext /*context*/)
  { /* register stuff */ }

  void Stop(BundleContext /*context*/)
  { /* cleanup */ }




CPPMICROSERVICES_DECLARE_SERVICE_INTERFACE(_service_interface_type, _service_interface_id)

Declare a service interface id.

This macro associates the given identifier _service_interface_id (a string literal) to the interface class called _service_interface_type. The Identifier must be unique. For example:

#include "cppmicroservices/ServiceInterface.h"

struct ISomeInterace { ... };

CPPMICROSERVICES_DECLARE_SERVICE_INTERFACE(ISomeInterface, "com.mycompany.service.ISomeInterface/1.0")

The usage of this macro is optional and the service interface id which is automatically associated with any type is usually good enough (the demangled type name). However, care must be taken if the default id is compared with a string literal hard-coding a service interface id. E.g. the default id for templated types in the STL may differ between platforms. For user-defined types and templates the ids are typically consistent, but platform specific default template arguments will lead to different ids.

This macro is normally used right after the class definition for _service_interface_type, in a header file.

If you want to use CPPMICROSERVICES_DECLARE_SERVICE_INTERFACE with interface classes declared in a namespace then you have to make sure the CPPMICROSERVICES_DECLARE_SERVICE_INTERFACE macro call is not inside a namespace though. For example:

#include "cppmicroservices/ServiceInterface.h"

namespace Foo
  struct ISomeInterface { ... };

CPPMICROSERVICES_DECLARE_SERVICE_INTERFACE(Foo::ISomeInterface, "com.mycompany.service.ISomeInterface/1.0")

  • _service_interface_type: The service interface type.
  • _service_interface_id: A string literal representing a globally unique identifier.