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