#include with <> or "" ?

Discussion in 'C++' started by saneman, Aug 1, 2008.

  1. saneman

    saneman Guest

    I have a folder 'app' containing a file 'main.cpp' and a subfolder 'types'
    (containing various header files). In main.cpp some header files from the
    subdir 'types' are included like:

    1)
    #include<types/vector.h>
    #include<types/matrix.h>

    But I have to change them to

    2)
    #include "types/vector.h"
    #include "types/matrix.h"

    to make compilation work. I know that 1) worked earlier with the original
    makefile but I don't have that anymore. How is it possible to make the code
    compile with the version used in 1) again?

    I am currently working in MS Visual Studio 2008 and it seems that makefiles
    are generated automatically.
    saneman, Aug 1, 2008
    #1
    1. Advertising

  2. saneman

    Jerry Coffin Guest

    In article <48931c71$0$90271$>,
    says...
    > I have a folder 'app' containing a file 'main.cpp' and a subfolder 'types'
    > (containing various header files). In main.cpp some header files from the
    > subdir 'types' are included like:
    >
    > 1)
    > #include<types/vector.h>
    > #include<types/matrix.h>
    >
    > But I have to change them to
    >
    > 2)
    > #include "types/vector.h"
    > #include "types/matrix.h"
    >
    > to make compilation work.


    This is what you almost certainly _should_ do. To make it work with the
    angle brackets, you have to lie to the compiler and tell it that the
    current diretory (i.e. the parent of your 'types' directory) contains
    "system" headers. That's typically done with the the '-I' compiler flag,
    though that varies and isn't really topical here anyway.

    --
    Later,
    Jerry.

    The universe is a figment of its own imagination.
    Jerry Coffin, Aug 1, 2008
    #2
    1. Advertising

  3. saneman

    James Kanze Guest

    On Aug 1, 4:44 pm, Victor Bazarov <> wrote:
    > saneman wrote:
    > > I have a folder 'app' containing a file 'main.cpp' and a
    > > subfolder 'types' (containing various header files). In
    > > main.cpp some header files from the subdir 'types' are
    > > included like:


    > > 1)
    > > #include<types/vector.h>
    > > #include<types/matrix.h>


    > > But I have to change them to


    > > 2)
    > > #include "types/vector.h"
    > > #include "types/matrix.h"


    > > to make compilation work. I know that 1) worked earlier with
    > > the original makefile but I don't have that anymore. How is
    > > it possible to make the code compile with the version used
    > > in 1) again?


    > > I am currently working in MS Visual Studio 2008 and it seems
    > > that makefiles are generated automatically.


    > The difference in processing of the angle-bracket type
    > inclusion directives and the double-quote type is
    > *implementation-defined*.


    In theory. In practice: includes in a <> are searched first in
    a list of directories that you provide (via -I or /I options,
    depending on the compiler), then in some standard system places
    (where the compiler is installed, then /usr/include under most
    Unix; under Windows, at least with VC++, I think the contents of
    the environement variable INCLUDE). An include "" first
    searches in the directory where the file containing the include
    was situated, and then acts exactly like an include <>.

    Some compilers have additional options to modify this somewhat
    (e.g. adding a directory which is only used by include ""), but
    I've yet to find a compiler which didn't support the above.

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
    James Kanze, Aug 1, 2008
    #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. Danny Anderson
    Replies:
    5
    Views:
    496
    Victor Bazarov
    Aug 15, 2003
  2. Rolf Magnus
    Replies:
    2
    Views:
    599
    Karl Heinz Buchegger
    Nov 28, 2003
  3. Elie Nader
    Replies:
    1
    Views:
    635
  4. Aguilar, James
    Replies:
    2
    Views:
    685
    Aguilar, James
    Jul 16, 2004
  5. Andreas Bogenberger
    Replies:
    3
    Views:
    903
    Andreas Bogenberger
    Feb 22, 2008
Loading...

Share This Page