Re: headerfiles and make?
- From: jt@xxxxxxxxxxx (Jens Thoms Toerring)
- Date: 11 Aug 2008 19:52:25 GMT
saneman <asdff@xxxxxxx> wrote:
"darren" <minofifa@xxxxxxxxx> skrev i en meddelelse
news:df5fd6b5-953c-459e-809d-472b1930947f@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Aug 11, 6:47 am, David Schwartz <dav...@xxxxxxxxxxxxx> wrote:
On Aug 11, 3:08 am, "saneman" <as...@xxxxxxx> wrote:
I have a sourcefile main.cpp and a headerfile types.h which I include in
main.cpp. In the headerfile I define some types used in main.cpp. I have
created a makefile containing:
all: main
main: main.cpp
g++ main.cpp -o main
when I type make it compiles fine eventhough I don't write any
dependency on
the types.h. How can I compile using the above makefile when types.h is
not
mentioned?
I'm not sure I understand your question. Is your question "my makefile
is broken, why does it work?" If so, the answer is that it does not
work. Do a 'make', then modify 'types.h'. Then do a 'make' again. You
will see taht the file is not compiled again even though it should be.
No I think you are referring to how the compiler knows to include your
header file even though you didn't specify it in your makefile? I'm
definately no expert on this but I think the #include directive you
used in your source code tells the compiler to look for it. It looks
in the current directory for it "." if no path is specified.
Yes this seems to be the case. I have always thought that headerfiles should
be supplied in a makefile, but it seems that this is not necessary.
Since a Makefile isn't necessary for compiling a program the header
file must be found by the compiler on its own. The '#include' di-
rectlive tells the compiler to look for a header file and evaluate
its content immediately. Makefiles have nothing to do with it. It
works whether you use a Makefile or not.
You should put the header files into the dependencies in a Makefile
to ensure that files that include the header file get recompiled if
the header file has been changed. Make doesn't look into the source
files all by itself to check which header files get included, so it
has no idea if a certain source file includes a header file and that
this source file then should be recompiled when the header file got
changed. It's your resonsibility to tell make that there's this de-
pendency.
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@xxxxxxxxxxx
\__________________________ http://toerring.de
.
- References:
- headerfiles and make?
- From: saneman
- Re: headerfiles and make?
- From: David Schwartz
- Re: headerfiles and make?
- From: darren
- Re: headerfiles and make?
- From: saneman
- headerfiles and make?
- Prev by Date: Re: Ascii to binary translator, has any one heard this?
- Next by Date: Re: headerfiles and make?
- Previous by thread: Re: headerfiles and make?
- Next by thread: Re: headerfiles and make?
- Index(es):
Relevant Pages
|