Stop recompiling if unchanged header codes?

Discussion in 'C++' started by Bryan Parkoff, Apr 5, 2005.

  1. "Load" and "Load2" are bound to "Include" while "Main" accesses variable
    from "Include". I can only modify one source code before C++ compiler can
    be able to compile one source code at this time so it does not need to
    recompile all unmodified source codes. If I add or modify one header code,
    it causes C++ Compiler to recompile all unmodified source codes. Why do it
    do this?
    How can I tell C++ Compiler's option to stop deleting all *.obj before
    recompiling? All *.obj should remain unmodified while only one header code
    can be compiled to create one object before one object can be linked to all
    unmodified objects.
    Please look at my code below for an example. Please let me know if
    there is a way.

    Bryan Parkoff

    // Include.h
    #if !defined(INCLUDE_H)
    #define INCLUDE_H

    extern int Total;
    extern int Number;
    extern int Number2;

    void Run(void);

    #endif // !defined(INCLUDE_H)

    // Include.cpp
    #include "Include.h"
    #include "Load.h"
    #include "Load2.h"

    int Total = 10;
    int Number = 12345;
    int Number2 = 67890;

    void Run(void)
    {
    Num();
    Num2();
    }

    // Load.h
    #if !defined(LOAD_H)
    #define LOAD_H

    void Num(void);

    #endif // !defined(LOAD_H)

    // Load.cpp
    #include "Load.h"
    #include "Include.h"

    void Num(void)
    {
    Number *= Total;
    }

    // Load2.h
    #if !defined(LOAD2_H)
    #define LOAD2_H

    void Num2(void);

    #endif // !defined(LOAD2_H)

    // Load2.cpp
    #include "Load2.h"
    #include "Include.h"

    void Num2(void)
    {
    Number2 *= Total;
    }

    // Main.cpp
    #include <stdio.h>
    #include "Include.h"

    int main(void)
    {
    printf("Hello...%d %d\n", Number, Number2);
    Run();
    printf("Hello...%d %d\n", Number, Number2);
    return 0;
    }
    Bryan Parkoff, Apr 5, 2005
    #1
    1. Advertising

  2. Bryan Parkoff schrieb:
    > "Load" and "Load2" are bound to "Include" while "Main" accesses variable
    > from "Include". I can only modify one source code before C++ compiler can
    > be able to compile one source code at this time so it does not need to
    > recompile all unmodified source codes. If I add or modify one header code,
    > it causes C++ Compiler to recompile all unmodified source codes. Why do it
    > do this?

    If you modify Include.h both Include.cpp and Main.cpp need to be
    recompiled. If you modify Load.h or Load2.h it should only recompile
    Include.cpp

    > How can I tell C++ Compiler's option to stop deleting all *.obj before
    > recompiling? All *.obj should remain unmodified while only one header code
    > can be compiled to create one object before one object can be linked to all
    > unmodified objects.

    Sorry, I don't really understand that sentence...headers are not
    compiled, a translation unit is compiled. A translation unit consists
    of a source (e.g. .cpp) file and everything directly or indirectly
    #included by that source file.
    If your IDE or "make" program invokes the compiler to recompile all
    source files instead of only the ones that #include a changed header, it
    does a poor job at determining dependencies. Either way, this is
    specific to your IDE or "make" and as such not topical here - it's not a
    C++ language issue. You will likely find a solution in a newsgroup
    dedicated to your toolchain.

    Cheers,
    Malte
    Malte Starostik, Apr 5, 2005
    #2
    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. Greg  --
    Replies:
    4
    Views:
    2,152
  2. Ahmed Jewahar
    Replies:
    1
    Views:
    4,734
    S. Justin Gengo [MCP]
    Jan 23, 2006
  3. Kevin D.
    Replies:
    4
    Views:
    352
    Kevin D.
    Mar 8, 2006
  4. Replies:
    2
    Views:
    2,818
    Malcolm
    Aug 20, 2005
  5. Allen
    Replies:
    1
    Views:
    641
    Mark Rae [MVP]
    Dec 3, 2007
Loading...

Share This Page