如何使用ld链接类似puts这样的builtin function?
一个简单问题.我想通过编译和链接两步来得到二进制文件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 编辑 ] 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的例子)
页:
[1]