Linux-kernel mailing list archive 1999-36,: Re: Some general LINUX questions on compiling and header files

# Re: Some general LINUX questions on compiling and header files

Zack Weinberg (zack@bitmover.com)
Thu, 09 Sep 1999 10:37:13 -0700

- Messages sorted by: [ date ][ thread ][ subject ][ author ]
- Next message: Alan Cox: "Re: Adding Serial Drivers to Linux Kernels"
- Previous message: fdavis112@juno.com: "imm.c compile errors, 2.3.17"

mike burrell wrote:
> Bret Indrelee (breti@bit3.com) said:
> > I've been looking around and haven't been able to find a few
> > things on Linux that I was expecting to find.
> >
> > 1. Is there a standard preprocessor token you can check for to
> > know that the compilation is on Linux? I'm looking for something
> > like the __sun token that is predefined by the compiler, so I can
> > put conditional code in a module I share amoungst multiple
> > operating systems.
>
> take a look at your /usr/lib/gcc-lib/*/*/specs file. the important
> line is: specs:-D__ELF__ -Dunix -Di386 -D__i386__ -Dlinux
> -Asystem(posix)
>
> so, yes, '#ifdef linux' will work (assuming everyone's specs file is
> like mine, hee hee)

They aren't, and the gcc people have been trying to get rid of the
defines without underscores for YEARS. Don't make their job harder.
You want #ifdef __linux__.

"gcc -E -dM - </dev/null" is an easier way to find out what's predefined.

> > 2. Where is the <stddef.h> header file required by ANSI C? I looked in
> > /usr/include and didn't see it.
>
> perhaps you should look in /usr/include/linux

Nope. /usr/lib/gcc-lib/i486-linux/2.7.2.3/include. "i486-linux" and
"2.7.2.3" may be different depending on your compiler. You don't need
any special command line switches to make the compiler find it.

This is a good place to point out that except in very specific unusual
contexts, user space code should never include linux/whatever.h or
asm/whatever.h. There will be a sys/whatever.h or net/whatever.h (the
name might be slightly different) that has what you want.

> > 3. In kernel code, are you supposed to directly read jiffies or
> > should you use a routine to access it? If so, what is the name of
> > the routine? On other operating systems, they use a routine to
> > access the information. From what I've seen, it looks like it is
> > just directly accessed in Linux.
>
> that's what it looks like to me too. i'm not exactly the best
> person to ask, though :)

I get the same impression. There are special routines (macros
actually) for *comparing* jiffies values: you'll see things like

if (time_before(timeout, jiffies)) { ... }

where timeout has been set previously.

> > 4. When compiling a kernel module, what special flags are
> > required? I would expect to have to put in '-r -nostdlib' at the
> > very least.

You don't actually _link_ a kernel module. The appropriate switches
are something like -c -D__KERNEL__ -DMODULE and possibly -DMODVERSIONS.

For this, I would look at the sources for pcmcia-cs-3.0.x, it compiles
a bunch of modules outside the kernel tree. Doing so is not trivial.

zw

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

- Next message: Alan Cox: "Re: Adding Serial Drivers to Linux Kernels"
- Previous message: fdavis112@juno.com: "imm.c compile errors, 2.3.17"