1.4 Setting Up a Compiler

The following sections explain how to set up various compilers for NLM development.

NOTE:If you have instructions for setting up a compiler for NLM development, which is not included in this section and that you would like to share with other CLib developers, please post these instructions in the CLib newsgroup.

Currently, we have instructions for the following compilers:

1.4.1 Setting Up CodeWarrior for NLM Development

You should install the following items on your development machine in the order listed:

See the CodeWarrior documentation for workstation requirements and installation instructions for CodeWarrior and the PDK. The PDK requires a NovellNDK environment variable. For the variable, enter NovellNDK. For its value, enter the location of the CLib SDK (default is c:\novell\ndk\nwsdk). You must either install the CLib NDK on the c: drive or modify some hard coded values in the project's nlm.def file that point to c:\novell\ndk\nwsdk.

The following instructions explain how to create a new stationary project with PDK 4.0 that you can use to compile the sample code.

  1. Start CodeWarrior.

  2. Select File > New.

  3. From the Project tab, select NetWare Stationary.

    NOTE:If you don't select NetWare Stationary, you cannot create a new project.

  4. In the Project name box, enter a name for the project, for example, Sample Code. In the Location box, enter the path where you want to store the project's files, and click OK.

  5. In the New Project window, select Server > CLib > Generic NLM C, and then OK.

  6. Expand NetWare SDK Libraries. If you do not plan to use the CodeWarrior integrated debugger or C++, delete the mwcrtl.lib and mwcrtld.lib files.

    NOTE:The sample code files will not compile without errors when these libraries are included.

  7. Add the clibpre.o file. Right click NetWare SDK Libraries, select Add Files from the drop down menu, browse to the c:\novell\ndk\nwsdk\imports directory, and select clibpre.o.

    If your NLM calls functions in other libraries such as eDirectory functions or Unicode functions, add these import files.

  8. Expand Source. You can compile the default program HelloWorld.c or your can select a sample code file.

    For a sample code file, delete HelloWorld.c. Then right click Source and from the drop down menu, select Add Files...

    Browse to the CLib sample code directory (the default location is c:\novell\ndk\samples\clib_sample\nlm), and select one of the sample code files to compile, for example, calendar.c.

    Each sample file is designed to be compiled as a separate NLM.

  9. Click the Generic C Build Settings... icon.

  10. In the Target category, click NLM Target, modify the fields, and click OK.

    For each NLM that you compile, you need to fill out the following NLM Target fields:

    • Output File—determines the name of the NLM.

    • Screen Name and Initial Screen Name—determines the default screen for the NLM. If the NLM receives input from a user, select User Specified and enter a name in the Initial Screen Name field. If the NLM receives no input from a user, you can select either Console (allows console output of messages) or No Default (prevents console output and input).

      For this sample code project, select User Specified and enter a name that matches the sample file you selected.

    • Initial Thread Name—specifies the prefix that is used to provide thread names. The names appear in the NetWare internal debugger, the CodeWarrior debugger, and the NetWare Remote Manager.

    • Stack Size—determines the maximum size of the stack. For the sample code, the default value of 8192 is adequate.

    • Copyright—enter your company's copyright string.

    • Description—supply a description that fits the NLM. This description appears in various NetWare management utilities.

    • Version—enter a version for the NLM. You must specify at least a major version number.

  11. Click the Make icon.

  12. When the compile completes, browse to the location of your project files.

  13. Copy the compiled *.nlm file to the sys:\system directory of your NetWare server.

    Other locations are possible, but if you create your own directory, you also need to add search paths or include the path in the load command.

  14. At the system console, load the NLM.

For more information, see the following:

  • Metrowerks manuals, especially the Targeting the NetWare Operating System PDK 4 manual. This manual explains all the Generic C Build Settings.

    If you prefer a command line interface, the Metrowerks manual explains how to access these development tools and their online documentation.

  • Metrowerks newsgroup.

1.4.2 Setting Up Open Watcom with Borland C++ Builder

The following steps explain how to build an NLM by compiling the code with Borland C++ Builder and by linking with WLINK from Open Watcom.

  1. Install Open Watcom 1.0 or later.

    Available from http://ww.openwatcom.org

  2. Download components from the Novell Developer Kit (cldap_all.exe, clib_all.exe, and ndslib_all.exe) available from http://developer.novell.com.

  3. Install the NDK components in c:\Program Files\NDK (or change the following linker definition file to match your location).

  4. Using Borland C++ Builder, create a file with the following code.

      #include <stdio.h>
      
      void main(void)
      {
         printf( "Hello, world\n" );
      }
      
  5. In the project options, turn off the “generate underscores” option.

  6. Compile the project. Don't build it, because all you need is the object file (hello.obj).

  7. Create a linker definition file for the Watcom Linker. It should look similar to the following:

      Option OSName = ’Novell NLM’
      Format Novell NLM ’Hello World!’
      
      Module CLib
      Module Threads
      
      Option CaseExact
      Import @C:\Progra~1\NDK\NDK\nwsdk\imports\clib.imp,
      @C:\Progra~1\NDK\NDK\nwsdk\imports\threads.imp
      
      Name   hello.nlm
      LibF   C:\Progra~1\NDK\NDK\nwsdk\imports\nwpre.obj
      File   hello.obj
      Option Copyright ’Public domain.  Hello World example’
      Option Map=hello.map
      Option NoDefaultLibs
      Option SymFile=hello.sym
      Option Version=1.00.00
      Option Stack=128k
      Option ScreenName ’Hello World Example’
      Option ThreadName ’HelloWorld_nlm’
      
  8. At a command prompt in the directory of the source code and linker definition file, enter

      wlink @link.lnk
      

    You should see the following output from this process:

      Open Watcom Linker Version 1.0
      Portions Copyright (c) 1985-2002 Sybase, Inc. All Rights Reserved.
      Source code is available under the Sybase Open Watcom Public License.
      See http://www.openwatcom.org/ for details.
      loading object files
      creating map file
      creating a Novell NLM executable
      
  9. When the linker is finished, copy the NLM to a NetWare 5.1 server or later and load it.

    The NLM creates a console screen, called Hello World Example, and prints “Hello, world” to this screen.

1.4.3 Using the WATCOM IDE

This section covers the following:

Setting Up Your Environment to Use WATCOM IDE

  1. Install the WATCOM development environment. Include Novell NLM as a target platform.

  2. Download and install the software for the NLM and NetWare Libraries for C, along with any other component that your NLM development requires, such as the NDS Libraries for C or the Novell Protocol Libraries for C. Further instructions assume that you install to the default location--C:\NOVELL\NDK.

  3. Modify your computer’s path statement to include the NDK tools directory (NWSDK/TOOLS).

    This must be done so that

    • The WATCOM Linker can find the Novell MAKEINIT file.

    • The Novell NLM tools (such as MSGLIB.EXE) are accessible

  4. Create a MAKEINIT configuration file and an ALL.IMP import file by running MAKEINIT.EXE, located in the NWSDK\TOOLS subdirectory.

Building HELLO.NLM with WATCOM IDE

  1. Create a directory for your project. (Example: C:\projects\hello)

  2. Activate the WATCOM IDE.

  3. From the menu bar, select "File / New Project."

  4. Specify the project directory (created in Step 1) and a project name. (Example: HELLO.WPJ)

  5. A "New Target" window appears, allowing you to specify a target name and an image type. (By default they should be set similar to the following: Target name = "hello", Image type = "NLM [.nlm]"). Click OK.

  6. A "Source Files" window appears, which is initially empty. Press the INSERT key. An "Add File(s) to..." window appears. Enter the name of the project’s first `C’ source file in the "File Name" field. (Example: HELLO.C). Add other `C’ source files as needed.

  7. Use the "Add File(s) to..." window to specify the location of the Novell prelude object file:

    • Set the "List Files of Type" field to All Files [*.*]

    • Set the "Drives" field and "Directories" field to NOVELL\NDK\NWSDK\IMPORTS

    • Specify the file CLIBPRE.OBJ and add it to the project

    Close the "Add File(s) to..." window.

  8. From the menu bar, select "Options / Link for NetWare Switches...," then deselect the "Incremental Linking [op inc]" option. Click OK.

    NOTE:In the Watcom 11 IDE, Incremental Linking [op inc] is turned on by default. This feature has been known to make Watcom’s Linker (WLINK) appear to be in an endless loop, never completing the link operation.

  9. Specify import files as explained in the following paragraphs, then click OK:

    • From the menu bar select "Options / Link for NetWare Switches..."

    • From the scroll bar select "2. Import, Export and Library Switches"

    • Check the box labeled "No default libraries [op nod]"

    • In the Import files(,):[imp] field, specify.IMP files as needed

      For example, to build the "Hello world" NLM, you must specify the following in the Import files(,):[imp] field):

        @$(nlm386imp)\threads.imp @$(nlm386imp)\nlmlib.imp
        

      Instead of specifying individual import files you can use @$(nlm386imp)\all.imp, which is a compilation of all the import files.

    (The macro nlm386imp value is defined in the Novell makeinit file, generated by the MAKEINIT.EXE file in the NWSDK\TOOLS directory.)

  10. From the menu bar select "Options / Link for NetWare Switches...," then from the scroll bar select "3. Advanced Switches." Check the box labeled "Case sensitive link[op c]."

    This option tells the Watcom Linker to consider case when resolving references to global symbols. For example, this will prevent calling FREE when you wanted to call free.

  11. From the menu bar select "Options / C Compiler Switches...." By default, "1. File Option Switches" is selected on the scroll bar. Set the Include directories:[-i] field to $(nlm386hdr).

    An IDE Request window might appear asking "Mark all .c files in ` ...’ for remake?" If it does, click Yes.

  12. From the menu bar select "Options / C Compiler switches...." Select "3. Source Switches." Click the radio button for 1 byte alignment [-zp1], then click OK. If an IDE Request window appears asking "Mark all .c files in ’...’ for remake?" click Yes.

    IMPORTANT:The Watcom 11 compiler structure alignment has changed from a default of 1 byte alignment [-zp1] (Watcom 10.6), to a default of 4 bytes [-zp4]. To build NLMs in Watcom 11, you must specify the 1 byte alignment option [-zp1].

  13. If necessary, edit one or more of the previously specified `C’ files. You can do so by double-clicking one of the files listed in the Source files: window. Here, for instance, is a simple "Hello world" example:

      #include <stdlib.h> 
      #include <stdio.h> 
       
      void main (void) 
       
      { 
         printf("Hellp world\n"); 
         return; 
      }
      
  14. Add the following function to one of your `C’ source files (for example HELLO.C):

      void WATCOM_Prelude(void) 
       
      { 
         return 
      }
      

    The Watcom 11 compiler constructs OBJ files from C source files. When the Watcom compiler is invoked from the IDE, a reference is automatically implied to an external __WATCOM_Prelude symbol. There is no known method of disabling this behavior from the IDE (even though the reference is not needed or even referenced in the C source). Therefore, your application must provide its own reference as a "shim" or "stub." This function will not be called by the Novell CLIBPRE.OBJ or Dynamic Linked Library NLMs.

    The example program HELLO.C now looks something like this:

      #include <stdlib.h> 
      #include <stdio.h> 
       
      void WATCOM_Prelude(void) 
       
      { 
         return 
      } 
       
      void main (void) 
       
      { 
         printf("Hello world\n"); 
         return; 
      }
      
  15. When source code edits are completed, save the file(s). Then from the menu bar select Targets / Make.

    If all went well, you will find a fully functional NLM in the target directory.

Installing Watcom v11 Optimized for NLM Development

This method is specific to the C language environment. It may seem possible to used the Watcom environment to write an NLM in C++, but there are known anomalies that cause NLMs written in C++ with Watcom to fail Novell NLM certification tests. If you are using C++ to develop NLMs consider using Meterowerks Code Warrior.

  1. Insert your Watcom 11 CD into your computer's CDROM drive.

    Click Start > Run > Browse. Select your CDROM drive, then select Setup.exe and click Open > OK.

  2. Specify the path at which the Watcom compiler will be installed or click OK to accept the default C:\WATCOM path.

  3. Specify the Selective installation type and click OK.

  4. Select which components will be installed. Select 32-bit compiler options: (deselect Include 16-bit compilers: if it is selected), uncheck the 32-bit MFC 4.1 support: option and click OK > Target.

  5. The next window lets you specify the target operating system. Deselect everything except NetWare and click OK > Other.

  6. In the Select other options: screen, deselect everything, and click OK > OK.

  7. A dialog appears saying "SETUP32 will now copy any selected files." Click OK. The install program will begin copying files as a bar chart tracks progress.

  8. A screen appears indicating that SETUP32 needs to modify the AUTOEXEC.BAT and CONFIG.SYS files. Confirm the modifications.

    If another dialog appears and tells you it will place the original AUTOEXEC.BAT and CONFIG.SYS files in two identified backup files, click OK.

  9. A dialog appears stating that you should reboot your computer so that changes will take effect. Click OK.

  10. Once the computer reboots, seven subdirectories in the specified installation directory are not needed. If you accepted the default directory, those subdirectories are the following:

    • \WATCOM\EDDAT
    • \WATCOM\H
    • \WATCOM\LIB286
    • \WATCOM\LIB386
    • \WATCOM\NLM
    • \WATCOM\NOVH
    • \WATCOM\NOVI

    Using Windows Explorer or the DOS deltree command, remove all seven. When you are finished, the following two will remain:

    • \WATCOM\BINNT
    • \WATCOM\BINW