makefile dependencies

This is a discussion on makefile dependencies within the C++ Programming forums, part of the General Programming Boards category; lets say i have a file, say main.cc, and it includes a file, say input.h, but input.h also includes io.h. ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    552

    makefile dependencies

    lets say i have a file, say main.cc, and it includes a file, say input.h, but input.h also includes io.h. Does that mean main.cc depends on io.h? If so, why.

  2. #2
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    If main.cc depends on input.h and input.h depends on io.h, then main.cc depends on io.h. If that is what you mean.

    Note that io.h doesn't need to be included witin main.cc also. If you include input.h, it is automatically included.

  3. #3
    *ClowmPimp*
    Guest
    let me reprase the question, if main.cc includes input.h in its dependency list, and input.h includes io.h in its dependency list, should main.cc also include io.h in its dependency list (assuming io.h is just some random header file, not the io.h included with the compiler). Note that main.cc contains no references to anything defined in io.h, just input.h.

    If so, then why. It seems to me that since main.cc doesn't contain any references to anything defined/declared in io.h, then it shouldn't include io.h in its dependency list.

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    206
    no, having the same header in every header file will lag your program cimpilation badly.

    Once I made a program with 2 header files, an engine i made and just aheader file for spare parts i made. They both linked to eachother and every other library(which also link to eachother). My c files also linked to my header files. Took me 10 minutes to compile my program. It was only around 1500 lines long. Sad. Very Sad.

  5. #5
    Registered User
    Join Date
    Dec 2001
    Posts
    206
    only link to input.h . Do not link to ios.h again. its not needed. does that answer ur question?

  6. #6
    Registered User
    Join Date
    Jan 2002
    Posts
    552
    >>only link to input.h
    hmmm, I'm not sure you understand my question.

    What I mean about dependency is that if i were to change a line of code in io.h but that changing that line did not require any modification to input.h, would i need to recompile my object code for main.cc?

  7. #7
    Registered User Liam Battle's Avatar
    Join Date
    Jan 2002
    Posts
    114
    ok, i think i know what ur asking.. if you change ANYTHING in any source file you used yes u need to recompile..
    also note when you include a .h the source code in the .h is pasted at the beginning of the source file you called it in..

    see the #include is a preprocessor statement saying everyting in the file goes here...

    ie:

    if myheader.h has this in it :

    cout <<" HELLO ";

    and you call it in source file main.cpp like this:

    #include <myheader.h>

    when you compile, the compiler goes through the preprocessor and finds the statement #include, now it says ok substitute everything in myheader.h and past it here , then remove the line #include <myheader.h>

    there ya go
    LB0: * Life once school is done
    LB1: N <- WakeUp;
    LB2: N <- C++_Code;
    LB3: N >= Tired : N <- Sleep;
    LB4: JMP*-3;

  8. #8
    Registered User
    Join Date
    Jan 2002
    Posts
    552
    Yes, thats what my instructor said. But what I said to him in response is that since main.cc doesn't reference anything in io.h, it doesnt matter if io.h is changed since main.cc has no use of anything in io.h. main.cc only calls classes and functions in input.h, so it only matters if definitions are changed in input.h, not io.h.

    [main.o] --> [input.o] --> [io.o]

    the only time that main.c should be recompiled is if the "interface" of the functions and classes change in input.o (ie. input.h changes). But since main.o references nothing in io.h/io.o, there is no need for main.o to be recompiled if the io.h changes

    If I'm wrong about this, i would like to know why.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with makefile
    By New_Programmer in forum C++ Programming
    Replies: 5
    Last Post: 03-31-2009, 05:55 PM
  2. Building a project using a Makefile
    By starcatcher in forum Windows Programming
    Replies: 2
    Last Post: 11-23-2008, 11:50 PM
  3. Makefile dependencies
    By taurus in forum C Programming
    Replies: 1
    Last Post: 11-09-2008, 12:17 AM
  4. Need help with Makefile
    By xshapirox in forum C++ Programming
    Replies: 14
    Last Post: 09-28-2004, 04:32 PM
  5. makefile dependencies (again)
    By *ClownPimp* in forum Linux Programming
    Replies: 2
    Last Post: 05-06-2002, 04:13 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21