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

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.


Sounds like your Makefile does not have dependencies configured correctly. That is what you should look into fixing.

If you really want to just force a rebuild rather than fix the underlying problem. Then you can do a make clean before your make all or, if the Makefile does not have a "clean" target, delete all the generated object files and libs/executables and then run make all again.


You can force make to rebuild everything using the --always-make command line option.

However, it sounds like you don't have your dependencies setup properly in your Makefile. If your code (.cpp files) actually include headers, then generally your target for compiling them should have a prerequisite on the header files that it includes.