【发布时间】:2014-02-17 17:28:47
【问题描述】:
我正在尝试在 NASM for Linux 中实现 C 函数“exp”。该函数接受一个双精度值 x,并返回一个双精度值 r = e^x,其中 e 是欧拉数。这是我的实现:
extern exp
SECTION .bss
doubleActual: resq 1
doubleX: resq 1
SECTION .text
main:
;some other code here
;calculate actual result
push doubleActual ; place to store result
push doubleX ;give the function what x is.
call exp
add esp, 8
在编译尝试时,我得到以下信息:
hw7_3.o: In function `termIsLess':
hw7_3.asm:(.text+0xf9): undefined reference to `exp'
这是指我实际调用 exp 的时间,这很奇怪,因为“extern exp”似乎工作得很好。我做错了什么?
【问题讨论】:
-
你是否链接到它定义的任何库?
-
使用 NASM for linux,这通常是没有必要的。例如,我可以“extern printf”,然后立即可以在我的代码中使用“call printf”。我认为这是 C 函数所独有的。
-
我猜你需要一个
-lm来链接 cmath 库。 -
请原谅我的无知,但我该怎么做呢?我以前不需要与 NASM 链接。我当前的编译例程是:“nasm -f elf32 name.asm”后跟“gcc -m32 name.o -o name”,其中name是我的程序名称。
-
你不需要为其他函数做任何事情,因为你让 GCC 为你做链接,它总是链接到
libc。但它并没有隐式链接到libm。