17.5 A Simple GNULinux Dynamic Module

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

17.5 A Simple GNU/Linux Dynamic Module

As an appetiser for working with dynamic loadable modules, here is a minimal module written for the interface used by the loader in the previous section:

 #include <stdio.h> int run (const char *argument) {   printf ("Hello, %s!\n", argument);   return 0; } 

Again, to compile on a GNU/Linux machine:

 $ gcc -fPIC -c simple-module.c $ gcc -shared -o simple-module.so 

Having compiled both loader and module, a test run looks like this:

 $ ./simple-loader simple-module World Hello, World!         => 0 

If you have a GNU/Linux system, you should experiment with the simple examples from this chapter to get a feel for the relationship between a dynamic module loader and its modules -- tweak the interface a little; try writing another simple module. If you have a machine with a different dynamic loading API, try porting these examples to that machine to get a feel for the kinds of problems you would encounter if you wanted a module system that would work with both APIs.

The next chapter will do just that, and develop these examples into a fully portable module loading system with the aid of GNU Autotools. In 20.1 A Module Loading Subsystem, I will add a more realistic mdoule loader into the Sic project last discussed in 12. A Large GNU Autotools Project.

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