我在我的项目中使用了函数pow() of math.h。我在-lm 中添加了标志到Makefile中,但是仍然遇到了试图运行make的以下错误
rudp_comm.c:(.text+0x3c1): undefined reference to `pow'
rudp_comm.c:(.text+0x458): undefined reference to `pow'如何解决这个问题?
这是完整的Makefile
CC := gcc
CFLAGS := -Wall -Wextra -Wpedantic -O3 -lm
SRC := client/client.c client/client_func.c client/client_func.h server/server.c server/server_func.c server/server_func.h common/conf.c common/conf.h common/file_list.c common/file_list.h common/rudp_comm.c common/rudp_comm.h
OBJ := $(SRC:.c=.o)
.PHONY: all
all: client/client server/server
client/client: client/client.o client/client_func.o common/conf.o common/file_list.o common/rudp_comm.o
client/client.o: client/client.c client/client_func.h common/rudp_comm.h
client/client_func.o: client/client_func.c client/client_func.h common/conf.h common/file_list.h
server/server: server/server.o server/server_func.o common/conf.o common/file_list.o common/rudp_comm.o
server/server.o: server/server.c server/server_func.h common/rudp_comm.h
server/server_func.o: server/server_func.c server/server_func.h common/conf.h common/file_list.h
common/conf.o: common/conf.c common/conf.h
common/file_list.o: common/file_list.c common/file_list.h
common/rudp_comm.o: common/rudp_comm.c common/rudp_comm.h
clean:
rm -f client/*.o server/*.o common/*.o core
cleanall:
rm -f client/*.o server/*.o common/*.o core client/client server/server在rudp_comm.c中,我当然包括了库(#include "rudp_comm.h"),所以我真的猜不出问题是什么!
发布于 2018-01-09 18:42:38
-lm应该进入LDLIBS,而不是Makefile中的CFLAGS。
LDLIBS = -lm请参阅node/Implicit-Variables.html
尽管CFLAGS也被传递给编译器,但最后的CFLAGS提供了同等的功能)。
https://stackoverflow.com/questions/48174621
复制相似问题