Changed .h file to C ++ no need to compile again?

I have the following question. After successful compilation, if I compile it again after I just changed some content in one of the .h files, the computer will say:

make: do nothing for `all '.

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

+4
source share
5 answers

If you want your result to be updated when the header files change, you must add it to your dependency statement:

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

, , -, cpp. unix , cpp, ( ) "touch myprogram.cpp", , .

make Makefile, , , , . .

+4

, Makefile . , .

, . make clean make all , Makefile "" , / , make all .

+3

make , --always-make.

, , Makefile. ( .cpp) , , , , .

+2

, . -MD Makefile -include myfile.d Makefile ( *.d). , , *.d (, *.o) , make, .

. , , Makefile, , , , , , Makefile.

, gcc -MD -I. -c myfile.cpp -o obj/myfile.o, Makefile foo: myfile.cpp myfile.h.

, :

# Beginning of Makefile etc. etc.

# Only need to list all files once, right here.
SRCS = myfile.cpp myfile2.cpp

OBJS = $(SRCS:%.cpp=%.o)

# put .o and .d files in ./obj/
FULLOBJS = $(addprefix obj/,$(OBJS))

# rule to make object (*.o) files
$(FULLOBJS): obj/%.o:%.cpp
    gcc -MD -I. -c %< -o $@

# rule to make binary
foo: $(FULLOBJS)
    g++ -o $@ $(FULLOBJS)

# rule to clean (Note that it also deletes *.d files)
.PHONY: clean
clean:
    -rm -rf $(FULLOBJS) foo $(FULLOBJS:%.o=%.d)

# include dependency files (*.d) if available
-include $(FULLOBJS:%.o=%.d)
+1

, .h ?

... , , make ().

, , - , , , make.

:

# ... noise 

g++ -O3 -ggdb -std=c++14 -Wall -Wextra -Wshadow -Wnon-virtual-dtor -pedantic -Wcast-align -Wcast-qual -Wconversion -Wpointer-arith -Wunused -Woverloaded-virtual   -O0  lmbm101_11.cc -o lmbm101_11 -L../../bag -lbag_i686 -lnet_i686 -lposix_i686 -lzlib_i686 -lrt -pthread

# ...  more noise.

, "command" ( "g++" ) make.

, emacs Linux. .

, .

(.. make, make.)

0

All Articles