C++ plugins [core]

Under Linux, we can use dlopen() to load a .so file. We will be using that function to load our plugins.

The function takes care of executing the C++ initialization as required (and corresponding destructions on dlclose() calls.)

This means we can create a plugin simply by creating a listener that will receive signals from the other plugins and Snap! core. The listener is created as a global variable which the dlopen() function automatically initializes (and if necessary, the dlclose() will turn it off.)

The dlopen() gives you a choice in loading everything in LAZY mode and making all the symbols GLOBAL. We need both flags!

  1. If plugin A needs to call a function offered by plugin B that plugin B function must be globally available (in many cases, it is used to attach A to a signal offered by B.)
  2. When plugin A calls the function of plugin B, it needs to be defined. However, the loader of all the plugins does not know the order in which the plugins must be loaded and therefore we need the loader to use the lazy flag or loading A before B breaks.

Note that imposes a certain number of constrains and it is important to understand how the system manages the initialization process to avoid problems such as "function not found."

 

Snap! Websites
An Open Source CMS System in C++

Contact Us Directly