Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Header files with "header.h" or <header.h> ??

1 view
Skip to first unread message

mlt

unread,
Jan 31, 2009, 9:35:35 AM1/31/09
to
I have a header only library containing various .h files. One of the header
files, all.h, includes all the other header files. When I include all.h I
therefore get all the other header files.

all.h looks like this:

#include <header1.h>
#include <header2.h>
#include <header3.h>
#include <header4.h>


When I include the all.h in my application:

#include "all.h"

I get an error that header1.h cannot be found. But if I change all.h to:

#include "header1.h"
#include "header2.h"
#include "header3.h"
#include "header4.h"


I works fine. But I don't want to change all.h, so how do I use all.h
unchanged (with <> instead of "")??

Bo Persson

unread,
Jan 31, 2009, 9:49:50 AM1/31/09
to

You have to check with your compiler!

The only difference is that "" tells the compiler to first look
somewhere (implementation specific) and, if not found there, perform
another search just like for <>.


Bo Persson


Jean-Marc Bourguet

unread,
Jan 31, 2009, 9:54:32 AM1/31/09
to
"mlt" <as...@asd.com> writes:

Short answer: add -Idir to your compilation options (or equivalent with
your IDE GUI).

Long answer: the standard doesn't define where included files (the "" form)
and headers (the <> form) are searched, excepted that if no file is found
an header is searched.

In practice, most compilers will search files included with ""
- in the same directory as the file containing the directive
- in a user specified list of directories
- in a list of default directories
while header included with <> are searched in the two last lists. But
there are variations on that which may break your build if you depend too
much on the search order to resolve ambiguities. And most compilers also
have other possibilities.

Yours,

--
Jean-Marc

Sam

unread,
Jan 31, 2009, 9:57:02 AM1/31/09
to
mlt writes:

With most compilers, use the -I option to specify where the header files are
installed.

Pete Becker

unread,
Jan 31, 2009, 10:46:18 AM1/31/09
to
On 2009-01-31 09:35:35 -0500, "mlt" <as...@asd.com> said:

>
>
> I works fine. But I don't want to change all.h, so how do I use all.h
> unchanged (with <> instead of "")??

You really should change it. The convention is that < ... > is for
system-supplied headers and " ... " is for everything else. That way
your users won't run into the problem you've just seen.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

0 new messages