C API Reference -- Loadable C Module Development

### Loadable C Module Development

The AOLserver can be extended by loading one or more C modules dynamically. You write these modules using your ordinary C code development environment and compile them as shared library modules on Unix as described below.

Each module must include an initialization routine that typically calls one or more AOLserver C API functions for registering the procedures within your module. The procedures within your module can handle URLs (operation procedures) or do other special-purpose functions. To register a C function in your module with the AOLserver, pass a pointer to your function as an argument to one of the AOLserver C API registration functions.

Module initialization functions can also set up any state required by your functions. For example, the AOLserver database services module's initialization routine creates a pool of database connections.

#### Creating a Loadable Module

To create a dynamically loadable C module, compile your code and then link the resulting object module into a shared library module on Unix.

Your C source code file must include the `ns.h` header file, which can be found in the `include` subdirectory of the AOLserver home directory. To compile and link your module, use the following instructions specific to your architecture.

#### Compile on Alpha OSF 4.0 platform

- Compile using the optional DEC C compiler:

        % cc -std1 -pthread -I$NS_HOMOE/include -c mymodule.c -o

    mymodule.o

- Compile using the freely available GCC compiler:

        % gcc -D__alpha__ -D_REENTRANT -I$NS_HOME/include -c momodule.c
    -o mymodule.o

- Link:

        % ld -shared -expect_unresolved '*' -o mymodule.so mymodule.o

#### Compile on HP/UX 10.20 platform

- Compile using the optional HP-UX C comiler:

        % cc -Ae -D__hpux__ -D__hp10 +DAportable +z -I$NS_HOME/include

    -c mymodule.c -o mymodule.o

- Link:

        % ld -b -o mymodule.so mymodule.o

#### Compile on SGI IRIX 6.2 platform

- Compile using the optional SGI C compiler:

        % cc -32 -D_SGI_MP_SOURCE -I$NS_HOME/include -c mymodule.c -o

    mymodule.o

- Compile using the freely available GCC compiler:

        % gcc -D__unix__ -D__sgi__ -I$NS_HOME/include -c mymodule.c -o
    mymodule.o

- Link:

        % ld -shared -o mymodule.so mymodule.o

#### Compile on Solaris 2.6 platform

- Compile using the optional SUNWspro compiler:

        % cc -D_POSIX_PTHREAD_SEMANTICS -D_REENTRANT -KPIC

    -I$NS_HOME/include -c mymodule.c -o mymodule.o

- Compile using the freely available GCC compiler:

        % gcc -D__unix__ -D__solaris__ -fpic -I$NS_HOME/include -c

    mymodule.c o mymodule.o

- Link:

        % ld -dy -G -o mymodule.so mymodule.o

#### Compile on Linux platform

- Compile using the freely availble GCC compiler:

        % gcc -rdynamic -I$NS_HOME/include -D_REENTRANT -c mymodule.c

    -o mymodule.o

- Link:

        % gcc -rdynamic -shared -o mymodule.so mymodule.o

#### Using a Loadable Module

For each library you would like to have the AOLserver load at startup time, add an entry in the server's Module section in the AOLserver configuration file. The format of a load entry is a nickname for the module, an equal sign, the filename of the module, and, optionally, the name of an initialization routine in parentheses. For example:

        mymodule=mymodule.so(MyInit)

Module filenames typically end in .so on Unix platforms. If the module filename is not an absolute path name, the AOLserver searches for the module in the bin subdirectory of the AOLserver home directory. The name of the initialization routine defaults to "Ns_ModuleInit".

Top of Page
Copyright © 1998-99 America Online, Inc.