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).
精彩评论