未定义参考“POW”即使-lm是一个编译标志。 [C] [英] Undefined reference to 'pow' even though -lm is a compile flag. [C]

查看:202
本文介绍了未定义参考“POW”即使-lm是一个编译标志。 [C]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何理由CC -g -lm -DBLITZ_HOST_IS_LITTLE_ENDIAN会产生math.h中使用code有错误?是否有可能存在的CC 4.0.3(记录工作版本)和4.6.3(我目前的版本)?

Any reason cc -g -lm -DBLITZ_HOST_IS_LITTLE_ENDIAN would produce an error with code using math.h? Is it possible there's a difference between cc 4.0.3 (documented working version) and 4.6.3 (my current version)?

和makefile asm.c https://gist.github.com/3801291

makefile and asm.c https://gist.github.com/3801291

这是在Ubuntu 12.04

This is on ubuntu 12.04

我的终端输出的要点的意见。

My terminal output is a comment in the gist.

推荐答案

而不是

cc -g -lm -DBLITZ_HOST_IS_LITTLE_ENDIAN foo.c

尝试:

cc -g -DBLITZ_HOST_IS_LITTLE_ENDIAN foo.c -lm

当链接器搜索库,它连接在包含previously-未定义的符号定义模块。

When the linker searches a library, it links in modules that contain definitions for previously-undefined symbols.

如果链接器的搜索 -lm foo.o的,那么 POW() 还不是不确定的。相反,如果 foo.o的是第一位的,它取消定义 POW(),其中 -lm 就可以解决。

If the linker searches -lm before foo.o, then pow() is not yet undefined. Conversely, if foo.o comes first, it undefines pow(), which -lm can then resolve.

修改:为了实现在的makefile这个建议,进行这些更改:

EDIT: To accomplish this advice in your makefile, make these changes:

CFLAGS=-g -DBLITZ_HOST_IS_LITTLE_ENDIAN
LDLIBS=-lm

...

asm: asm.c
        $(CC) $(CFLAGS) asm.c $(LDLIBS) -o asm

这篇关于未定义参考“POW”即使-lm是一个编译标志。 [C]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆