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

Unix/Linux
基础篇:find技巧1
基础篇:find技巧2
对shutdown,halt,reboot,init的一点理解
grep的使用
多个文件函数互相引用的编译操作
SLES 相关的若干问题
精品推荐:命令大集合[分类整理]
红旗桌面版5.0(Code Name是Apatite)将在8月中旬发布第一个Snapshot版本
创建VLAN
VRRP
代理ARP
用iptables构建DMZ防火墙
netstat 使用详解
刚刚安装好php与apache,现将
外贸英语900句 之 价格Price
First use Linux
Linux下wu-ftpd的配置使用指南
Fc2下五笔输入法的问题
ProFTP配置文件
一步到位的 LAMP 安装脚本 (AMP部分)

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-01   浏览: 61 ::
收藏到网摘: 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