Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions
Privacy Policy




Back: A Module Loading Subsystem
Forward: Managing Module Loader Errors
FastBack: A Complex GNU Autotools Project
Up: A Module Loading Subsystem
FastForward: A Loadable Module
Top: Autoconf, Automake, and Libtool
Contents: Table of Contents
Index: Index
About: About this document

20.1.1 Initialising the Module Loader

Before using this code (or any other libltdl based module loader for that matter), a certain amount of initialisation is required:

  • libltdl itself requires initialisation.

    1. libltdl should be told to use the same memory allocation routines used by the rest of Sic.

    2. Any preloaded modules (see section 18.4 dlpreopen Loading) need to be initialised with LTDL_SET_PRELOADED_SYMBOLS().

    3. ltdl_init() must be called.

  • The module search path needs to be set. Here I allow the installer to specify a default search path to correspond with the installed Sic modules at compile time, but search the directories in the runtime environment variable `SIC_MODULES_PATH' first.

  • The internal error handling needs to be initialised.

Here is the start of the module loader, `sic/module.c', including the initialisation code for libltdl:

#  include <config.h>

#include "common.h"
#include "builtin.h"
#include "eval.h"
#include "ltdl.h"
#include "module.h"
#include "sic.h"


module_init (void)
  static int initialised = 0;
  int errors = 0;

  /* Only perform the initialisation once. */
  if (!initialised)
      /* ltdl should use the same mallocation as us. */
      lt_dlmalloc = (lt_ptr_t (*) (size_t)) xmalloc;
      lt_dlfree = (void (*) (lt_ptr_t)) free;

      /* Make sure preloaded modules are initialised. */

      last_error = NULL;

      /* Call ltdl initialisation function. */
      errors = lt_dlinit();

      /* Set up the module search directories. */
      if (errors == 0)
          const char *path = getenv (SIC_MODULE_PATH_ENV);

          if (path != NULL)
            errors = lt_dladdsearchdir(path);

      if (errors == 0)
        errors = lt_dladdsearchdir(MODULE_PATH);

      if (errors != 0)
        last_error = lt_dlerror ();


      return errors ? SIC_ERROR : SIC_OKAY;

  last_error = multi_init_error;
  return SIC_ERROR;

This document was generated by Gary V. Vaughan on February, 8 2006 using texi2html

  Published under the terms of the Open Publication License Design by Interspire