Logo next up previous index
Next: 4. Debugging Up: cross under linux Previous: 2. Preparing the Build   Index

Subsections

3. Using the Netware cross-compiler


3.1 Preparing the PATH environment variable

You'll usually want to add the directory containing the cross- compiler to the PATH variable. There are two relevant directories:

If you want things like man i386-netware-nm to work, add to the MANPATH:

      export MANPATH=/opt/cross/man:/opt/cross/i386-netware/man

3.2 Basic use

To do a basic compilation, just use the usual compiler command:

   i386-netware-g++ -o hello.nlm hello.cpp

This will create a new executable NLM file from a C++ source file, using a lot of default settings.


3.3 Compilation using a Makefile

One possible scenario is to use a fairly standard Makefile, but using several parameters on the command line to tell make that you do not want to compile with the native tools, but with the cross compiler. Example:

   all: hello

   hello.o: hello.cpp

Using this Makefile, just calling make will create the application hello with the default system compiler. However calling make with special parameters will cause creation of the NLM:

   # Delete temp files.
   make \
     CC=i386-netware-gcc \
     CXX=i386-netware-g++ \
     AR=i386-netware-ar \
     CROSS=i386-netware- \
     hello

   mv hello hello.nlm

Since this is all quite a bit lengthy, you might want to create a shell-script to combine these settings with additional parameters from the command line. With the example script make_nlm.sh included in the cross_nlm-1.2.0.tar.gz you may just use the command:

    make_nlm.sh clean all


3.3.1 Make variables

A note on make variables: Variables passed to make as environment variables such as

export AR=i386-netware-ar
make

Will be overwritten if the Makefile contains commands such as AR=ar. Compared to that, variables defined on the make command line will not be overwritten.


3.4 Using configure scripts

configure scripts are a major aid in porting C and C++ software to different platforms. Since a C source code cannot detect if the compilation environment offers a certain header file or a certain function, this is done using a script that runs on a POSIX-Style shell interpreter, usually the bash. The script is conventionally called configure.

The technology mostly works by doing test-compiles accessing the required function. If the test compile succeeds, then a #define HAVE_something line is added to a file like config.h. In most cases, the final Makefile is created from Makefile.in by configure. Using this technology usually saves a lot of work in comparison to manually configuring a compilation environment.

For configure scripts to work properly, you need to make the script call the ``right'' compiler, this is usually done using command line parameters and environment variables.

   ./configure --help
   export CC=i386-netware-gcc
   export AR=i386-netware-ar
   ./configure --prefix=/opt/cross/i386-netware

3.4.1 GNU configure scripts created by autoconf

The basic use of cross-compilation with configure scripts is to use the command line parameters -build and -host. Don't forget to put the /opt/cross/bin directory onto the PATH.

  ./configure \
   --target=i386-netware \
   --build=i686-pc-linux-gnu \
   --host=i386-netware

You might find useful additional informations in the directory libs and the incomplete wxWindows port to Netware available by download from http://www.herdsoft.com/ftp/downloads.html#cross .


3.5 Conditional compilation

The Netware cross compiler defines the pre-defined macros __netware__ and __i386__ for pieces of code that need special treatment for Netware.


3.6 XDC data

To mark NLMs as Thread-Safe, Thread-Unsafe etc., NLMs may includes additional informations in an XDC-File, which is to be generated by mpkxdc.exe and linked using the xdcdata option used in the linker definition file.

Novell does not offer a Linux version of mpkxdc.exe yet, but GŁnter Knauf http://www.gknw.de/development/prgtools/mkxdc.zip has written a simple replacement with an incomplete feature set for the same purpose and included into cross_nlm by friendly permission. Just use the name of the .xdc file as a command line option to the i386-netware-gcc compiler such as:

   i386-netware-mkxdc -u hello.xdc
   i386-netware-gcc -o hello.nlm hello.cpp hello.xdc

See also http://developer.novell.com/support/sample/tids/txdc1/txdc1.htm .

3.7 Creating shared libraries

As a special means of easyfying the use of shared libraries, i386-netware-gcc understands the -shared option to create a shared library that exports all public functions defined by the NLM.

    i386-netware-gcc -shared -o library.nlm file1.c file2.c file3.c

3.8 Using shared libraries

cross_nlm simulates linking to a NLM by specifying the NLM on the command line. However for NLMs created by a different compiler this oftenly fails, and the import list has to be specified instead. The library specified must have the .nlm file extension, else it will not be properly recognized.

    i386-netware-g++ -o application application.cpp library.nlm

3.9 Controlling NLM configuration

Details for newly created NLM files are usually defined in a linker-description file with .def file extension. Howeber that model is not easy to use and not support by open source programs. For that reason cross_nlm specified those additional informations from the following locations:

Variable Command line parameter meaning
NLM_COPYRIGHT -nlm-copyright=string Copyright String to be displayed by netware when loading the NLM
NLM_DESCRIPTION -nlm-description=string NLM Description string to be placed inside of the NLM
NLM_SCREENNAME -nlm-screenname=string Name of the Screen that will display NLM output
NLM_VERSION -nlm-version=num,num NLM Version Number


3.10 Disabeling debug infos

When linking applications to NLMs, the default is to include all available debug infos created from compilation of source files with the -g switch into the resulting NLM. Since most libraries are compiled with debug infos, this usually means that the resulting binary will also contain a lot of debug infos. Later removal of debug infos from the NLM is not supported. To create a NLM without debug infos the -s or -strip command line option must be used.

    i386-netware-gcc -s -o hello.nlm hello.c


next up previous index
Next: 4. Debugging Up: cross under linux Previous: 2. Preparing the Build   Index
Herd Software Development, 28. March 2003, http://www.herdsoft.com/