免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3702 | 回复: 1
打印 上一主题 下一主题

redhat 交叉编译 gcc设置 [复制链接]

论坛徽章:
0
1 [报告]
发表于 2009-03-25 00:11 |显示全部楼层

  1. torshie@Orz:/tmp$ cat t.c
  2. int f() {
  3.         int x = 35;
  4.         int y = 20;
  5.         return x + y;
  6. }
  7. torshie@Orz:/tmp$ cat main.c
  8. extern int f();
  9. int main() {
  10.         printf("%d\n", f());
  11. }
  12. torshie@Orz:/tmp$ gcc t.c -m32 -c
  13. torshie@Orz:/tmp$ gcc main.c -m64 -c
  14. main.c: In function ‘main’:
  15. main.c:3: warning: incompatible implicit declaration of built-in function ‘printf’
  16. torshie@Orz:/tmp$ gcc main.o t.o
  17. /usr/bin/ld: i386 architecture of input file `t.o' is incompatible with i386:x86-64 output
  18. collect2: ld returned 1 exit status
  19. torshie@Orz:/tmp$ objcopy t.o -O elf64-x86-64
  20. torshie@Orz:/tmp$ gcc main.o t.o
  21. torshie@Orz:/tmp$ ./a.out
  22. Segmentation fault
  23. torshie@Orz:/tmp$ gcc t.c -O2 -c -m32
  24. torshie@Orz:/tmp$ objcopy -O elf64-x86-64 t.o
  25. torshie@Orz:/tmp$ gcc t.o main.o
  26. torshie@Orz:/tmp$ ./a.out
  27. 55
  28. torshie@Orz:/tmp$ uname -a
  29. Linux Orz 2.6.27-7-generic #1 SMP Tue Nov 4 19:33:06 UTC 2008 x86_64 GNU/Linux
  30. torshie@Orz:/tmp$ cat /proc/cpuinfo |grep 'model name'
  31. model name        : Intel(R) Core(TM)2 Duo CPU     E8200  @ 2.66GHz
  32. model name        : Intel(R) Core(TM)2 Duo CPU     E8200  @ 2.66GHz
复制代码

论坛徽章:
0
2 [报告]
发表于 2009-03-25 00:15 |显示全部楼层
n久以前看到的帖子,例子已经在了,剩下自己看着搞吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP