开发者

GCC linker issue with -lm flag

I'm having issues with the GCC linker, specifically using the -lm flag since I'm using some functions from math.h. I get the following errors:

main.c:(.text+0x8e5): undefined reference to `floor'

main.c:(.text+0x901): undefined reference to `ceil'

Here's the relevant portion of my makefile:

myprogram: main.o
    gcc -Wall -pedantic -o myprogram main.o

main.o: main.c foo.h bar.h
    gcc -Wall -pedantic -lm main.c

Probably something silly I'm overlooking, but I'm definite开发者_如何学Goly not an expert when it comes to makefiles.


Furthermore, library specifications have to come after the objects referencing them (cf. Linker flags in wrong place ).


-lm is a linker flag, so you should add it to the linking rule above (i.e., you added it to the wrong rule).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜