gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:34:29 26 4
gpt4 key购买 nike

我正在尝试在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com