[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#533124: c99-gcc -I breaks POSIX conformance



Package: gcc
Version: 4:4.3.3-8
Severity: normal

POSIX.1-2008 says[*]:

  -I  directory
    Change the algorithm for searching for headers whose names are not
    absolute pathnames to look in the directory named by the directory
    pathname before looking in the usual places. Thus, headers whose
    names are enclosed in double-quotes ( "" ) shall be searched for
    first in the directory of the file with the #include line, then in
    directories named in -I options, and last in the usual places. For
    headers whose names are enclosed in angle brackets ( "<>" ), the
    header shall be searched for only in directories named in -I
    options and then in the usual places. Directories named in -I
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    options shall be searched in the order specified. Implementations
    shall support at least ten instances of this option in a single
    c99 command invocation.

[*] http://www.opengroup.org/onlinepubs/9699919799/utilities/c99.html

So, the directories specified by -I should have the precedence over
the usual places. However, this is not the behavior of gcc; from the
gcc 4.3.2 man page:

  -I dir
    Add the directory dir to the list of directories to be searched for
    header files.  Directories named by -I are searched before the
    standard system include directories.  If the directory dir is a
    standard system include directory, the option is ignored to ensure
    that the default search order for system directories and the
    special treatment of system headers are not defeated .  If dir
    begins with "=", then the "=" will be replaced by the sysroot
    prefix; see --sysroot and -isysroot.

As you can see, there is a difference for standard system include
directories, for which the option is ignored.

To reproduce this bug:
1. Install libgmp3-dev
2. Touch /usr/local/include/gmp.h
3. Compile the following program tst.c with "c99 -I/usr/include tst.c"

----------------------------------------
#include <gmp.h>

int main (void)
{
  __GNU_MP_VERSION;
  return 0;
}
----------------------------------------

I get the following failure:

vin:~> c99 -I/usr/include tst.c
tst.c: In function 'main':
tst.c:5: error: '__GNU_MP_VERSION' undeclared (first use in this function)
tst.c:5: error: (Each undeclared identifier is reported only once
tst.c:5: error: for each function it appears in.)

To fix this bug, either gcc needs to be made POSIX-conforming or the
c99-gcc script should be improved, e.g. by parsing the options and
modifying the CPATH and C_INCLUDE_PATH environment variables to make
sure that the -I directories are searched in the correct order.

For instance, "C_INCLUDE_PATH=/usr/include c99 tst.c" compiles the
program without any error.

-- System Information:
Debian Release: squeeze/sid
  APT prefers oldstable
  APT policy: (500, 'oldstable'), (500, 'unstable'), (500, 'stable'), (1, 'experimental')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.26.5-20080922 (SMP w/2 CPU cores; PREEMPT)
Locale: LANG=POSIX, LC_CTYPE=en_US.ISO8859-1 (charmap=ISO-8859-1)
Shell: /bin/sh linked to /bin/bash

Versions of packages gcc depends on:
ii  cpp                           4:4.3.3-8  The GNU C preprocessor (cpp)
ii  gcc-4.3                       4.3.3-10   The GNU C compiler

Versions of packages gcc recommends:
ii  libc6-dev [libc-dev]          2.9-13     GNU C Library: Development Librari

Versions of packages gcc suggests:
ii  autoconf                  2.63-3         automatic configure script builder
ii  automake1.9               1.9.6+nogfdl-3 A tool for generating GNU Standard
ii  bison                     1:2.4.1.dfsg-1 A parser generator that is compati
ii  flex                      2.5.35-7       A fast lexical analyzer generator.
ii  gcc-doc                   5:2            documentation for the GNU compiler
ii  gcc-multilib              4:4.3.3-8      The GNU C compiler (multilib files
ii  gdb                       6.8-3          The GNU Debugger
ii  libtool                   2.2.6a-4       Generic library support script
ii  make                      3.81-5         The GNU version of the "make" util
ii  manpages-dev              3.21-1         Manual pages about using GNU/Linux

-- no debconf information



Reply to: