Re: Some general LINUX questions on compiling and header files

Michael Meissner (meissner@cygnus.com)
Thu, 9 Sep 1999 16:16:03 -0400


> > 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)

Actually the *predefines line is special. The driver program will go through
and any -D<name> options will also do -D__<name>__ and -D__<name>. The ISO C
rules require that no name in the user's namespace be defined at the time of
compilation, so if you use -ansi, the -D<name> is not passed to the
preprocessor. Thus it is never a good idea to use:

#ifdef linux

You should instead use:

#ifdef __linux__

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

GCC provides stddef.h. Look in:

/usr/lib/gcc-lib/*/*/include/

-- 
Michael Meissner, Cygnus Solutions
PMB 198, 174 Littleton Road #3, Westford, Massachusetts 01886
email: meissner@cygnus.com	phone: 978-486-9304	fax: 978-692-4482

- 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/