16.5. A Simple GNU/Linux Dynamic Module

As an appetizer for working with dynamic loadable modules, here is a minimal module written for the interface used by the loader in the preceding 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 ...

Get GNU Autoconf, Automake, and Libtool now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.