next up previous
Next: Initialization and Shutdown Up: PARAPIN: A Parallel Port Previous: Parapin Basics

Subsections


Compiling and Linking Your Programs to Use Parapin

Note: Please see the file INSTALL, located in the root directory of the parapin distribution, for details on building and installing parapin on your system.

The C Library Version

The user-space version of Parapin is compiled and linked very much like any other C library. If you installed Parapin on your system using ``make install'', the library (libparapin.a) was probably installed in /usr/local/lib. The header file with the library's function prototypes and other definitions, parapin.h, is in the location given in the parapin Makefile as $\(LINUX\_SRC\)/include.

Important: Parapin must be compiled with gcc using compiler optimization of -O or better. This is because Parapin uses the inb and outb functions that exist only with compiler optimization.

To use the library, first make sure to #include parapin.h in your C source file. When linking, add -lparapin along with any other libraries you might be using.

The Kernel Module Version

As with the C library version, kernel source code that uses Parapin must #include parapin.h. Make sure that __KERNEL__ is defined before the include statement.

Important: Parapin must be compiled with gcc using compiler optimization of -O or better. This is because Parapin uses the inb and outb functions that exist only with compiler optimization.

Linking is a little more complicated. As with any other interdependent kernel modules, there are actually two ways of using parapin with your Linux device driver:

The Makefiles that come with Parapin compiles Parapin into its own independent module, called kparapin.o. This module can be inserted into the kernel using modprobe (as described in the first method). If you'd rather use the second method, and link Parapin directly with your device driver module instead, do the following:

  1. Copy parapin.c into your driver's source directory.
  2. In your driver's Makefile, compile kparapin.o from parapin.c, with the -D__KERNEL__ directive, but without the -DMODULE directive.
  3. Link kparapin.o with all the other object files that make up your driver.

If your driver only consists of one other source file, and you have never linked multiple .o's together into a single kernel module, it's easy. First, compile each .c file into a .o using gcc -c (the same as with normal C programs that span multiple source files); then, link all the .o's together into one big .o using ld -i -o final-driver.o component1.o component2.o component3.o ....

Important note: Whichever method you use, Parapin also requires functions provided by the standard Linux kernel module parport. Make sure you insert the parport module with the modprobe command before inserting any modules that use Parapin; otherwise, you will get unresolved symbols.

The device driver 'parapindriver'

When building a userspace program that will make use of the parapindriver interface to kparapin, you must include parapindriver.h. This header file defines the device-specific ioctl commands used to communicate with the device driver. It also includes parapin.h, so your program can make use of all the ``LP_*'' constants. The parapindriver system calls take arguments using these constants and pass them unchanged down to the kparapin routines.


next up previous
Next: Initialization and Shutdown Up: PARAPIN: A Parallel Port Previous: Parapin Basics
Al Hooton 2004-11-16