我在使用 GCC 链接器时遇到问题,特别是在使用 -lm
标志时,因为我正在使用 math.h 中的一些函数。我收到以下错误:
main.c:(.text+0x8e5): undefined reference to `floor'
main.c:(.text+0x901): undefined reference to `ceil'
这是我的 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
可能我忽略了一些愚蠢的事情,但我绝对不是 makefile 方面的专家。
最佳答案
此外,库规范必须位于引用它们的对象之后(参见 Linker flags in wrong place)。
关于c - GCC 链接器问题与 -lm 标志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4964786/