首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何解决“对pow的未定义引用”(已经与-lm链接)?

如何解决“对pow的未定义引用”(已经与-lm链接)?
EN

Stack Overflow用户
提问于 2018-01-09 18:34:45
回答 1查看 188关注 0票数 0

我在我的项目中使用了函数pow() of math.h。我在-lm 中添加了标志Makefile中,但是仍然遇到了试图运行make的以下错误

代码语言:javascript
复制
rudp_comm.c:(.text+0x3c1): undefined reference to `pow'
rudp_comm.c:(.text+0x458): undefined reference to `pow'

如何解决这个问题?

这是完整的Makefile

代码语言:javascript
复制
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"),所以我真的猜不出问题是什么!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-01-09 18:42:38

-lm应该进入LDLIBS,而不是Makefile中的CFLAGS

代码语言:javascript
复制
LDLIBS = -lm

请参阅node/Implicit-Variables.html

尽管CFLAGS也被传递给编译器,但最后的CFLAGS提供了同等的功能)。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48174621

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档