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

M

mlt

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

Bo Persson

mlt said:
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
 
J

Jean-Marc Bourguet

mlt said:
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,
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,835
Latest member
KetoRushACVBuy

Latest Threads

Top