一、line1的源碼
- ?line1.h
#ifndef _LINE_1_H
#define _LINE_1_H void line1_print(const char *strMsg);
#endif
- line1.cpp
#include "line1.h"
#include <stdio.h>
void line1_print(const char *strMsg)
{printf("This is line1 print %s.\r\n",strMsg);
}
二、line2的源碼
- line2.h
#ifndef _LINE_2_H
#define _LINE_2_H void line2_print(const char *strMsg);
#endif
- line2.cpp
#include "line2.h"
#include <stdio.h>
void line2_print(const char *strMsg)
{printf("This is line2 print %s.\r\n",strMsg);
}
三、main的源碼
- main.cpp
#include "line1.h"
#include "line2.h"int main(int argc,char **argv)
{line1_print("hello runfarther");line2_print("hello runfarther");return 0;
}
Makefile一般的格式是:
target:components rule
二、$@、$^、$<
這三個分別表示:
- $@??????????--代表目標文件(target)
- $^????????????--代表所有的依賴文件(components)
- $<???????????--代表第一個依賴文件(components中最左邊的那個)。
簡化的Makefile文件為:
main.out:main.o line1.o line2.og++ -o $@ $^
main.o:main.c line1.h line2.hg++ -c $<
line1.o:line1.c line1.hg++ -c $<
line2.o:line2.c line2.hg++ -c $<
- Makefile的編寫