免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 4593 | 回复: 13

难度...GCC extern函数 [复制链接]

论坛徽章:
1
申猴
日期:2014-02-11 14:50:31
发表于 2009-08-03 23:10 |显示全部楼层
10可用积分
在一个c里面:

int test()
{
  printf("hi,unix\n");
}

gcc有没有什么参数可以使得该函数是extern的?  xlC又是有什么参数?

注意不是改代码....

论坛徽章:
0
发表于 2009-08-03 23:13 |显示全部楼层
gcc不能,没用过AIX。

论坛徽章:
2
青铜圣斗士
日期:2015-11-26 06:15:59数据库技术版块每日发帖之星
日期:2016-07-24 06:20:00
发表于 2009-08-03 23:16 |显示全部楼层

回复 #1 chenzhanyiczy 的帖子

默认就是extern的。

test.c
int test() { printf("\n") }

main.c
int test(void);
int main(void) { test(); return 0; }

gcc -c test.c
gcc -c main.c
gcc main.o test.o

就可以链接成功。

论坛徽章:
1
申猴
日期:2014-02-11 14:50:31
发表于 2009-08-03 23:18 |显示全部楼层
原帖由 prolj 于 2009-8-3 23:13 发表
gcc不能,没用过AIX。


为什么不能?

论坛徽章:
1
申猴
日期:2014-02-11 14:50:31
发表于 2009-08-03 23:18 |显示全部楼层
原帖由 OwnWaterloo 于 2009-8-3 23:16 发表
默认就是extern的。

test.c
int test() { printf("\n") }

main.c
int test(void);
int main(void) { test(); return 0; }

gcc -c test.c
gcc -c main.c
gcc main.o test.o

就可以链接成功。


假如换成是static呢,而不是extern?

论坛徽章:
2
青铜圣斗士
日期:2015-11-26 06:15:59数据库技术版块每日发帖之星
日期:2016-07-24 06:20:00
发表于 2009-08-03 23:21 |显示全部楼层

回复 #5 chenzhanyiczy 的帖子

你是说……

test.c
static int test() {  }

main.c
int test(void);
int main(void) { test(); return 0; }

要这样也行?  还不能改test.c的代码???

……

gcc -c main.c
gcc -Dstatic=extern -c test.c
gcc main.o test.o

-_- b;

论坛徽章:
1
申猴
日期:2014-02-11 14:50:31
发表于 2009-08-03 23:25 |显示全部楼层
-Dstatic=extern 这个是宏吗?

但还是改了test.c

论坛徽章:
0
发表于 2009-08-03 23:25 |显示全部楼层
原帖由 chenzhanyiczy 于 2009-8-3 23:25 发表
-Dstatic=extern 这个是宏吗?

但还是改了test.c

gcc的参数

论坛徽章:
1
申猴
日期:2014-02-11 14:50:31
发表于 2009-08-03 23:33 |显示全部楼层
-D就是定义宏的啊

论坛徽章:
1
申猴
日期:2014-02-11 14:50:31
发表于 2009-08-03 23:34 |显示全部楼层
在google搜了老半天了,没有任何结果,特别是xlC,少得可怜
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP