Stop recompiling if unchanged header codes?

B

Bryan Parkoff

"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;
}
 
M

Malte Starostik

Bryan said:
"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
 

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,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top