和往常一样,我们将从著名的 “Hello world” 程序开始。hello.nlm 的源代码可以在 nlm-samples 包中找到。您可以从 ftp://ftp.penguin.cz/pub/users/mhi/nlm/ 下载它。
#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 */ }
# # hello.def - NLM Header definition file for nlmconv(1) # Copyright (c) 2000 Martin Hinner <martin@hinner.info> # # 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 <martin@hinner.info>" # (c) ... DESCRIPTION "Simple 'Hello world' NLM module." # title of nlm SCREENNAME "System Console" # Default screen name MODULE CLIB,THREADS # req'd modules
# makefile for "hello world" NLM CC = gcc CFLAGS = -Wall -O2 -g -I/usr/nwsdk/include/ -nostdinc -fno-builtin -fpack-struct hello.nlm: hello.o hello.def nlmconv --output-target=nlm32-i386 -T hello.def hello.o: hello.c $(CC) $(CFLAGS) -c hello.c
您必须将这些参数传递给 gcc
将 hello.nlm 复制到您的 NetWare 服务器上的 SYS:\SYSTEM 目录。然后,在系统控制台上,键入 “load hello.nlm”。如果一切顺利,您应该看到 NLM 版本信息、版权信息和 “Hello world”。