-
打印环境变量和内置变量方法:
make -p
-
常见的隐含规则
1、CPP文件编译命令的自动推导
CXXFLAGS = -Wall -Wfatal-errors
LDFLAGS = -lopencv_core -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc
COMPILE.cpp = $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
OUTPUT_OPTION = -o $@
%.o: %.cpp
$(COMPILE.cpp) $(OUTPUT_OPTION) $<
#展开后为
#$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<
示例:
#make padding.o
g++ -Wall -Wfatal-errors -c -o padding.o ./src/padding.cpp
2、.o文件生成可执行文件的规则
LINK.o = $(CC) $(LDFLAGS) $(TARGET_ARCH)
%: %.o
$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@
#展开
#$(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LOADLIBES) $(LDLIBS) -o $@
示例:
gcc -lstdc++ -lopencv_core -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc padding.o -o padding
3、CPP文件直接生成可执行程序的规则
LINK.cpp = $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)
%: %.cpp
$(LINK.cpp) $^ $(LOADLIBES) $(LDLIBS) -o $@
#展开后
#$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH) $^ $(LOADLIBES) $(LDLIBS) -o $@
示例:
g++ -Wall -Wfatal-errors -lopencv_core -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc ./src/padding.cpp -o padding