To get the GNU C compiler, you must install the Solaris OS at the Developer level or above. Follow the instructions in Chapter 2, Installing With the Solaris Installation Program (Tasks), in Solaris 10 Installation Guide: Basic Installations. Select Custom Install, and select the Developer cluster or above. The GNU C compiler is installed in /usr/sfw.
Use the -D_KERNEL option to indicate that this code defines a kernel module. These examples show options that are required for correct functionality of the result.
If you are compiling for a 64-bit SPARC architecture, use the following build commands:
% gcc -D_KERNEL -m64 -mcpu=v9 -mcmodel=medlow -fno-pic -mno-fpu -ffreestanding -nodefaultlibs -c mydriver.c % /usr/ccs/bin/ld -r -o mydriver mydriver.o |
You might also want to use the -mtune=ultrasparc option and the -O2 option.
If you are compiling for a 64-bit x86 architecture, use the following build commands:
% gcc -D_KERNEL -m64 -mcmodel=kernel -mno-red-zone -ffreestanding -nodefaultlibs -c mydriver.c % /usr/ccs/bin/ld -r -o mydriver mydriver.o |
You might also want to use the -mtune=opteron option and the -O2 option.
If you are compiling for a 32-bit architecture, use the following build commands:
% gcc -D_KERNEL -ffreestanding -nodefaultlibs -c mydriver.c % /usr/ccs/bin/ld -r -o mydriver mydriver.o |
For more information on these and other options, see the gcc(1) man page. See also the GCC web site at http://gcc.gnu.org/. More information about using the gcc compiler with the Solaris OS is on the OpenSolaris web site at http://opensolaris.org/os/community/tools/gcc/.