免费注册 查看新帖 |

Chinaunix

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

用gcc怎么生成bin格式文件 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-02-05 16:47 |只看该作者 |倒序浏览
想用gcc得到bin格式的文件,出现找不到库。
使用文本编辑器写一个test.c:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(int argc, char* argv[])
{
        char buf[4];
        memset(buf,0,sizeof(buf));
        printf("hello word";
}


[root@202 test]# gcc -c test.c
[root@202 test]# ld -o test -Ttext 0x0 -e main test.o
test.o(.text+0x2: In function `main':
: undefined reference to `memset'
test.o(.text+0x3: In function `main':
: undefined reference to `printf'

ld出现找不到库,请问怎么修改?

objcopy –R .note –R .comment –S –O binary test test.bin

论坛徽章:
3
2015年迎新春徽章
日期:2015-03-04 09:56:11数据库技术版块每日发帖之星
日期:2016-08-03 06:20:00数据库技术版块每日发帖之星
日期:2016-08-04 06:20:00
2 [报告]
发表于 2009-02-05 18:19 |只看该作者
并没有bin格式的文件.
后缀名为bin的文件是出于各种目的的文件.

论坛徽章:
3
戌狗
日期:2014-09-10 17:07:162015年辞旧岁徽章
日期:2015-03-03 16:54:15wusuopu
日期:2016-06-17 17:43:45
3 [报告]
发表于 2009-02-05 19:24 |只看该作者
原帖由 goon86 于 2009-2-5 16:47 发表
ld -o test -Ttext 0x0 -e main test.o

没加libc
  1. ld -o tttest -Ttext 0x0 -e main test.o -lc
复制代码

论坛徽章:
3
2015年迎新春徽章
日期:2015-03-04 09:56:11数据库技术版块每日发帖之星
日期:2016-08-03 06:20:00数据库技术版块每日发帖之星
日期:2016-08-04 06:20:00
4 [报告]
发表于 2009-02-05 20:54 |只看该作者
你既然ld,ld不是自然认识libc的,应该-lc

论坛徽章:
0
5 [报告]
发表于 2009-02-05 20:58 |只看该作者
《自己动手写操作系统》,不愿意查手册就看这个。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP