Resorter Resorter - 1 year ago 78
C++ Question

Changed .h file in C++ does not need to be compiled again?

I have the following question. After a successful compilation, if I compile it again after I only change some content in one of the .h files, the computer says:

make: Nothing to be done for `all'.

Can I force the compiler to compile again even if I have only modified the .h files?

Answer Source

If you want your output to be updated when header files change, then you have to add it to your dependency statement:

 myprogram: myprogram.cpp myprogam.h
      c++ -o myprogram myprogram.cpp

Typically we don't do it this way because the code that does things stays in the cpp file. If you are on unix and want to force a rebuild, just touch a cpp file to update its timestamp (forcing a rebuild) with "touch myprogram.cpp", for example, or delete your existing executable.

If you are using make without a Makefile, letting it infer dependencies, it will probably not infer the header dependencies. In this case, either blow away your executable or touch your source file.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download