c - 如何在 NASM for Linux 中正确使用 C 函数 "Exp"?

标签 c linux nasm exp

我正在尝试在 Linux 的 NASM 中实现 C 函数“exp”。该函数采用 double 值 x,并返回 double 值 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”似乎工作得很好。我做错了什么?

最佳答案

通过http://www.linuxtopia.org/online_books/an_introduction_to_gcc/gccintro_17.html ....

我需要使用 gcc 执行以下操作:

gcc -m32 name.o -lm -o name

“-lm”标签是链接 C 数学库的快捷方式,它独立于标准库。

关于c - 如何在 NASM for Linux 中正确使用 C 函数 "Exp"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21835538/

相关文章:

c++ - C 结构 (C++ POD) 和 google protobufs 之间的转换?

c - 为什么在 C 中使用 clone 函数需要这个指针算法?

c++ - 使用宏访问 C 中的结构成员名称

c - 逻辑运算符和增量运算符

linux - 我可以从 linux 上的函数地址获取模块句柄吗?

assembly - 如何在编译时获取标签的地址

assembly - 在 nasm 中寻址数组元素

python - 重定向 Python 解释器的 IO

linux - 在编译过程中,它在 "cannot find -lexecinfo"处失败

c - 是否可以从汇编文件中引用 C 枚举?