Next Previous Contents

3. First step: Hello world

As usually, we will start with the famous "Hello world" program. The source code for hello.nlm is available in the nlm-samples package. You can download it from ftp://ftp.penguin.cz/pub/users/mhi/nlm/.

3.1 hello.c - Source file


#define N_PLAT_NLM                                /* Define dest. platform */

#include <nwconio.h>                              /* ConsolePrintf */

int
main (int argc, char **argv)
{
  int i;

  ConsolePrintf ("\rHello world!\n\n");           /* print on system console */

  ConsolePrintf("Arguments:\n");                  /* all arguments */
  for (i=0;i<argc;i++)
   ConsolePrintf("argv[%u]=\"%s\"\n",i, argv[i]);

  return 0;                                       /* exit NLM */
}

3.2 hello.def - NLM header file


#
# hello.def - NLM Header definition file for nlmconv(1)
# Copyright (c) 2000 Martin Hinner <mhi@penguin.cz>
#

# define startup object files
INPUT   hello.o
INPUT   /usr/nwsdk/lib/prelude.o            # clib startup code

# all imported functions and import lists
IMPORT @/usr/nwsdk/imports/clib.imp         # Functions in CLIB.NLM
IMPORT @/usr/nwsdk/imports/threads.imp      # Functions in THREADS.NLM

# NLM header...
OUTPUT  hello.nlm                           # output file
TYPE 0                                      # Ordinary NLM
VERSION 1,0,0                               # Version 1.0
COPYRIGHT "Copyright (c) 2000 Martin Hinner <mhi@penguin.cz>" # (c) ...
DESCRIPTION "Simple 'Hello world' NLM module." # title of nlm
SCREENNAME "System Console"                 # Default screen name

MODULE CLIB,THREADS                         # req'd modules

3.3 Makefile


# makefile for "hello world" NLM

CC = gcc
CFLAGS = -Wall -O2 -g -I/usr/nwsdk/include/

hello.nlm:      hello.o hello.c hello.def
        nlmconv --output-target=nlm32-i386 -T hello.def

hello.o:        hello.c
        $(CC) $(CFLAGS) -c hello.c

3.4 Testing the module

Copy the hello.nlm to SYS:\SYSTEM directory on your NetWare server. Then on system console type "load hello.nlm". If everything went fine, you should see NLM version info, copyright message and "Hello world".


Next Previous Contents