www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/11/15/07:00:33

Date: Sun, 15 Nov 1998 13:37:52 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: Daniel McGrath <dmcg6174 AT yahoo DOT com>
cc: djgpp AT delorie DOT com
Subject: Re: Problem with nested #include's
In-Reply-To: <364e0e09.936581@news.liii.com>
Message-ID: <Pine.SUN.3.91.981115133732.1381m-100000@is>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com

On Sat, 14 Nov 1998, Daniel McGrath wrote:

> Suppose I have a source file foo.c, and in the file it says
> 
>   #include "bar.h"
> 
> where bar.h is a header file.  In this header file, bar.h, it says
> 
>   #include "baz.h"
> 
> Now, when I run the preprocessor using "gcc" or "cpp", I will get an
> error message like this:
> 
>   In file included from foo.c:LINE_NUMBER:
>   bar.h:LINE_NUMBER: baz.h: No such file or directory (ENOENT)
> 
> I get this error message _even when the file baz.h actually does
> exist_.

In what directory does baz.h exist?  Is it in the same place where
bar.h resides?  If it is, it should be something funny in your source
(like if there's an invisible character on the line which includes
"bar.h").

If baz.h is NOT in the same directory where bar.h is, then you should
be aware of the following excerpt from the cpp docs, where the
``#include "foo"'' feature is described:

     This variant is used for header files of your own program.  It
     searches for a file named FILE first in the current directory,
     then in the same directories used for system header files.  The
     current directory is the directory of the current input file.

Note the last sentence: when "bar.h" is processed, the ``directory of
the current input file'' is the one where bar.h is kept, not the one
where you keep the source file that included bar.h.

The usual way to handle these cases is to use #include <bar.h> and
<baz.h>, and add -I. to the GCC command line.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019