尽管使用了 -lm,但对 powl 和 log10 的引用仍未定义(Trusty 通过 Travis)

尽管使用了 -lm,但对 powl 和 log10 的引用仍未定义(Trusty 通过 Travis)

使用 Trusty 编译 C 文件时cc -lm -std=c99 ...,出现以下错误:

fraction_math.c:(.text+0x5cb): undefined reference to `powl'

/tmp//fetlang_build//fet_obj_debug//core/chain.c.o: In function `num_to_cstr':

chain.c:(.text+0x682): undefined reference to `log10'

collect2: error: ld returned 1 exit status  

但是,我可以在 Debian Stretch 或 macOS Sierra 中执行完全相同的构建,它会找到符号。

答案1

我从评论中将其添加到此处,因为它不是作为答案发布的。必须阅读评论才能解决问题。我正在研究 regldg (http://regldg.com/docs/command_line_args.php) 也遇到了同样的问题。我确实添加了#include "stdint.h"代码,但我怀疑-lm在命令后手动添加代码才能解决问题

“在其他所有操作之后加上 -lm 就可以解决这个问题。”

对于 regldg 来说,解决方案是:

gcc -O3 -Wall -g alt.o altlist.o build_structs.o char_set.o data.o debug.o grouplist.o grouprecord.o main.o memory.o parse_regex.o program_args.o re_perm.o silist.o tnode.o vlr.o vlrlist.o -o regldg -lm

答案2

步骤:1. 在文件位置打开终端 2. 命令 --> gcc filename.c -lm 3. 在文件位置创建 a.out 文件 4. 执行文件命令 --> ./a.out 5. 查看输出

相关内容