test1.c
#include <stdio.h>
#include "test.h"
void test1(){
printf(add1);
}
test2.c
#include <stdio.h>
#include "test.h"
void test2(){
printf(add2);
for(; i > 0; i--){
printf("%d-", i);
}
}
test.c
#include <stdio.h> #include "test.h" char add1[] = "www.shellbox.cn/n";
char add2[] = "www.scriptbox.cn/n";
int i = 10; extern void test1(); extern void test2(); int main(){ test1(); printf("ok/n"); test2(); printf("%d/n", i); return 0; }
test.h
#ifndef _TEST_H_ #define _TEST_H_ extern char add1[];
extern char add2[]; extern int i; void test1(); void test2(); #endif
Makefile
test: test.o test1.o test2.o
gcc -o test test.o test1.o test2.o
test1.o: test1.c
gcc -c -o test1.o test1.c
test2.o: test2.c
gcc -c -o test2.o test2.c
test.o: test.c
gcc -c -o test.o test.c
clean:
rm test test.o test1.o test2.o
执行:
make test
运行:
./test
原文:http://www.cnblogs.com/fordreamxin/p/4607165.html