本文介绍了编译程序中的多个C文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下两个文件:
file1.c中
INT的main(){
富();
返回0;
}
file2.c中
无效美孚(){ }
我可以编译和两个文件链接在一起,让 file1.c中
将识别富
功能,无需添加的extern
?
更新的雏形。
解决方案
You don't need an extern
, but file1.c must see a declaration that foo()
exists. Usually this declaration is in a header file.
To add a forward declaration without using a header file, simply modify file1.c to:
int foo(); // add this declaration
int main(){
foo();
return 0;
}
这篇关于编译程序中的多个C文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!