上实验课,让做多文件编译,半天没反应,老师问为啥,她能想到大家没动静的原因是c基础不扎实吗?
我也不会
搜了半天,找到解药了
主文件里要有函数原型,函数的实现可以放在其他文件里。也不用在主文件里去自己include
example:
helloword.c
void t1();
void t2();
void t3();
int main(){
t1();
t2();
t3();
return 0;
}
func.c
#include "stdio.h"
void t1(){
printf("mY nAME iS wUjI\n");
}
void t2(){
printf("form class 666\n");
}
void t3(){
printf("happy\n");
}
编译的时候,就
gcc -c func.c
gcc -c helloword.c
然后链接、运行
gcc func.o helloword.o -o TheRes.out
./TheRes.out