当前位置: 首页 > 图文教程 > 操作系统 > Unix/Linux > 多个文件函数互相引用的编译操作

Unix/Linux
linux紧急救援模式
论学习
让你firefox快起来
我的fedora core 3汉化之旅
几个在线英汉字典网站
JPEG 简易文档 V2.11(转贴)
加罗华简介
怎么消除linux下的屏幕偏移现象和调整屏幕刷新率?
我哥哥去了西安做生意去了
2005第二号公告
squid的配置文件
尖峰时刻
grub硬盘安装hiweed-debian-desktop_0.55
hiweed0.55下xmms菜单乱码的解决
proftp详细配置一览
使用者管理--sudo
Windows 2003和Redhat Linux7.3安装问题
Find命令使用详解
今天开始找工作了
如何对系统做镜像以提高系统高可用性和性能

Unix/Linux 中的 多个文件函数互相引用的编译操作


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-01   浏览: 89 ::
收藏到网摘: n/a

在写程序的时候,会经常遇到文件a.c会调用b.c中的某一个函数func(),那么该如何来进行操作呢?答案是:合理的利用Makefile,而不是include,否则会报undefind symbol to _func().下面是详细的操作过程。
/*b.c*/
#include
int p=3;
int func(int i)
{return p*i;}
int setp(int i)
/*a.c*/
#include
extern int p;
extern int func(int i);
extern int setp(int i);//告诉系统这些函数在其他的文件当中
int main(int argc,char *argv[])
{
setp(4);
printf("%d",func(4));
}
/*Makefile*/
all: a
gcc -o a.o b.o
Then run make, run the programme, you will get result 16