17.3 Finding a Module

back: module access functions
forward: a simple gnu/linux module loader
 
fastback: a simple gnu/linux module loader
up: dynamic loading
fastforward: using gnu libltdl
top: autoconf, automake, and libtool
contents: table of contents
index: index
about: about this document

When you are writing a program that will load dynamic modules, a major stumbling block is writing the code to find the modules you wish to load. If you are worried about portability (which you must be, or you wouldn't be reading this book!), you can't rely on the default search algorithm of the vendor dlopen function, since it varies from implementation to implementation. You can't even rely on the name of the module, since the module suffix will vary according to the conventions of the target host (though you could insist on a particular suffix for modules you are willing to load).

Unfortunately, this means that you will need to implement your own searching algorithm and always use an absolute pathname when you call dlopen . A widely adopted mechanism is to look for each module in directories listed in an environment variable specific to your application, allowing your users to inform the application of the location of any modules they have written. If a suitable module is not yet found, the application would then default to looking in a list of standard locations -- say, in a subdirectory of the user 's home directory, and finally a subdirectory of the application installation tree. For application `foo' , you might use `/usr/lib/foo/module.so' -- that is, `$(pkglibdir)/module.so' if you are using Automake.

This algorithm can be further improved:

  • If you try different module suffixes to the named module for every directory in the search path , which will avoid locking your code into a subset of machines that use the otherwise hardcoded module suffix. With this in place you could ask the module loader for module `foomodule' , and if it was not found in the first search directory, the module loader could try `foomodule.so' , `foomodule.sl' and `foomodule.dll' before moving on to the next directory.
  • You might also provide command line options to your application which will preload modules before starting the program proper or to modify the module search path. For example, GNU M4, version 1.5, will have the following dynamic loading options:
 
 $ m4 --help Usage: m4 [OPTION]... [FILE]... ... Dynamic loading features:   -M, --module-directory=DIRECTORY  add DIRECTORY to the search path   -m, --load-module=MODULE          load dynamic MODULE from M4MODPATH ... Report bugs to <bug-m4@gnu.org>. 

This document was generated by Gary V. Vaughan on May, 24 2001 using texi2html


GNU Autoconf, Automake and Libtool
GNU Autoconf, Automake, and Libtool
ISBN: 1578701902
EAN: 2147483647
Year: 2002
Pages: 290

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net