Re: headerfiles and make?



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
.



Relevant Pages

  • Re: Preference: Header File OR Compile Flags?
    ... Do you like to create a header file with all the associated ... > the command line or from a makefile? ... Suppose I have a header, "porting.h" which contains all my system-specific ... flexibility to use a makefile to select between the options. ...
    (comp.lang.c)
  • Re: the gotoxy(int x, int y) function
    ... implementations do not come with it. ... to your compiler, operating system, and processor can be ... header file and expect it to work, ...
    (comp.lang.c)
  • Re: the gotoxy(int x, int y) function
    ... compiler doesn't define it in any header ... im a newbie here and to the C language, i understood your problem, as ... far as i know its in the conio.h header file both in C and C++, ...
    (comp.lang.c)
  • Re: size_t
    ... George wrote: ... need to include any header file in order to use size_t. ... VC2008 knows about size_t even without a header, because the compiler ...
    (microsoft.public.vc.language)
  • Re: header files including other files
    ... Really I guess I am asking advice about source code organisation. ... Now, in any particular module, the module header file declares exported ... compile it with no errors. ...
    (comp.arch.embedded)