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

Discussion in 'C++' started by mlt, Jan 31, 2009.

  1. mlt

    mlt Guest

    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 "")??
    mlt, Jan 31, 2009
    #1
    1. Advertising

  2. mlt

    Bo Persson Guest

    mlt wrote:
    > 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 "")??


    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
    Bo Persson, Jan 31, 2009
    #2
    1. Advertising

  3. "mlt" <> writes:

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


    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
    Jean-Marc Bourguet, Jan 31, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. crazyprakash
    Replies:
    4
    Views:
    3,363
    adrian
    Oct 30, 2005
  2. Replies:
    4
    Views:
    936
    M.E.Farmer
    Feb 13, 2005
  3. John Smith

    Header files included in header files

    John Smith, Jul 21, 2004, in forum: C Programming
    Replies:
    18
    Views:
    596
    Jack Klein
    Jul 24, 2004
  4. Replies:
    3
    Views:
    1,277
    Walter Roberson
    May 1, 2006
  5. Replies:
    3
    Views:
    1,431
    Rolf Magnus
    Jan 18, 2009
Loading...

Share This Page