HDK Technical Reference

Compiling kernel drivers

Drivers should always use the compiler, linker, and other tools that come from the same operating system release as the kernel and which were used to build the rest of the kernel. Other compilers can be used for compiling user-level applications on systems but should not be used for compiling drivers. Different compilers use different bitfield conventions and structure layouts; see ``Bitfields''. This can cause problems in kernel code, because the entire kernel is linked together as a single executable binary. This also means that it is not possible to create universal device driver binaries.

Note that kernel-level drivers must never call user-level libraries, so no -l options can be used on the compile line.

The sample drivers that are included on the HDK CD-ROM or the HDK homepage include sample Makefiles that can be studied for more details about compiling drivers.

This article covers the following topics:

SVR5 DDI C language compiler notes

The following command options are required when compiling DDI drivers:

specifies that this object will be linked into the kernel.

For example, -D_DDI=8. This is required for DDI 8 drivers and optional for DDI versions prior to version 8.

Alternately, the source code can include the following lines, before any header files are #included:

   #define _KERNEL
   #define _DDI 8
The _DDI option or line gives the ``major'' version number, such as 7 or 8; it does not use full version numbers such as 8.1 or 8mp.

SCO OpenServer 5 ODDI C language compiler notes

The following command options are used when compiling ODDI drivers:

specifies that the object will be linked into the kernel.

compile the driver for debugging.

Note that the idcomp compiler that is used to compile driver's space.c files is not an ANSI C compiler, so do not use C language facilities in space.c files or the header files they call unless it is defined in the Kernighan and Ritchie C Language. The main driver code should be compiled with the standard SCO OpenServer 5 C compiler which is ANSI compliant.

C++ compiler notes

See ``Writing drivers in C++'' for notes about writing drivers in C++.

© 2005 The SCO Group, Inc. All rights reserved.
OpenServer 6 and UnixWare (SVR5) HDK - June 2005