QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 2473|回复: 1

如何使用ld链接类似puts这样的builtin function?

[复制链接]
发表于 2008-8-23 16:56:47 | 显示全部楼层 |阅读模式
一个简单问题.
我想通过编译和链接两步来得到二进制文件a. 源程序是nasm的, 如下
---
;hello.asm
        section .text
        extern puts
        global main
_start:
        push dword msge;
        call puts;
        add esp, byte 4;
        ret;

msge :
        db "hello, world!", 0
===

生成 ``a'' 所用命令如下
---
nasm -f elf a.asm
ld -o a a.o
===

我得到如下错误信息
---
ld: warning: cannot find entry symbol _start; defaulting to 08048060
a.o: In function `_start':
a.asm : (.text+0x6) : undefined reference to `puts'
===

显然错误是由于不能链接puts造成的. 有没有什么简单的办法, 使得可以正确链接它呢?

[ 本帖最后由 JulianL 于 2008-8-23 17:00 编辑 ]
发表于 2008-8-27 10:55:49 | 显示全部楼层
  1. ld a.o -o a.out -lc -dynamic-linker /lib/ld-linux.so.2
复制代码


参考文献: Programming from the Ground Up
这本书电子版的官方下载地址是: http://savannah.nongnu.org/projects/pgubook/
遵循GNU FDL,所以可以免费下载传阅。
强烈推荐LZ看看。这方面的问题可以在这本书的第八章找到一些例子(是用printf的例子)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-3-29 09:57 , Processed in 0.083047 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表