linux中.d依赖文件的使用

test.cpp:

#include "it.h"  

 //#pragma comment(lib, "libit")

int main(void)  

{  

  myprint();  

  return 0;  

} 

it.h:

#include "d.h"
void myprint(void); 


it.cpp:

#include "it.h"  

 //#pragma comment(lib, "libit")

int main(void)  

{  

  myprint();  

  return 0;  

} 


d.h

:

#include <stdio.h>  


makefile:

OUT_NAME = test
SRC_DIR = ./testfold
OBJS = $(patsubst $(SRC_DIR)/%.cpp, $(INT_DIR)/%.o, $(wildcard $(SRC_DIR)/*.cpp))
test.d : test.cpp
	gcc -c -MMD test.cpp	
sinclude test.d
$(OUT_NAME) : test.o it.o
	$(CC) -o $@ $^ -L. -lit -lstdc++
test.o: test.cpp it.h
	gcc -c $<
it.o: it.cpp
	gcc -c $<


如果我注释掉:
gcc -c -MMD test.cpp

sinclude test.d

那么当我修改了d.h中的内容的时候并且test.cpp中的内容没有修改的时候,make test.d test那么不会重新编译test.cpp

如果加上了这两句,那么会重新编译,

gcc -c -MMD test.cpp


会产生test.d, 生成对应的c,cpp文件所依赖的头文件等信息


版权声明:本文为suhiymof原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。