文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>多个文件函数互相引用的编译操作

多个文件函数互相引用的编译操作

时间:2005-07-21  来源:heack

在写程序的时候,会经常遇到文件a.c会调用b.c中的某一个函数func(),那么该如何来进行操作呢?答案是:合理的利用Makefile,而不是include<b.c>,否则会报undefind symbol to _func().下面是详细的操作过程。

/*b.c*/

#include<stdio.h>

int p=3;

int func(int i)

{return p*i;}

int setp(int i)

{p=i;}

/*a.c*/

#include<stdio.h>

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

相关阅读 更多 +
排行榜 更多 +
<img preview="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" width="32" height="32" src="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" alt="弓箭勇者最新版" />

<img preview="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" width="32" height="32" src="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" alt="弓箭勇者最新版" />

飞行射击 下载
<img preview="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" width="32" height="32" src="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" alt="弓箭勇者最新版" />

<img preview="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" width="32" height="32" src="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" alt="弓箭勇者最新版" />

飞行射击 下载
<img preview="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" width="32" height="32" src="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" alt="弓箭勇者最新版" />

<img preview="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" width="32" height="32" src="http://pic.pdowncc.com/uploadimg/ico/2025/0523/1747993424374100.png" alt="弓箭勇者最新版" />

飞行射击 下载