C Makefile链接器错误- [英] C Makefile linker error -
问题描述
我在下面编写了Makefile.编译期间出现以下错误.我不确定IBS
是什么?它缺少LIBS
中的L
还是什么?
I'v written the Makefile below. I'm getting the following error during compilation. I'm not sure what IBS
is? Is it missing the L
from LIBS
or something?
关注的问题:
这是目录结构.
.
├── Makefile
└── src
├── include
│ └── utils.h
├── main.c
└── utils.c
但是,当我运行make时,这是输出.它似乎没有拾取并生成文件utils.c
吗?
However, when I run make, this is the output. It doesn't seem to be picking up and building the file utils.c
?
cc -I./src -I./src/include -I/usr/local/include/upm -MMD -MP -c src/main.c -o build/./src/main.c.o.o
cc -I./src -I./src/include -I/usr/local/include/upm -MMD -MP -c src/main.c -o build/./src/main.c.o.o
TARGET_EXEC ?= app.out
BUILD_DIR ?= ./build
SRC_DIRS ?= ./src
SRCS := $(shell find $(SRC_DIRS) -name *.cpp -or -name *.c -or -name *.s)
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
DEPS := $(OBJS:.o=.d)
INC_DIRS := $(shell find $(SRC_DIRS) -type d)
INC_FLAGS := $(addprefix -I,$(INC_DIRS)) -I/usr/local/include/upm
CPPFLAGS ?= $(INC_FLAGS) -MMD -MP
$(BUILD_DIR)/$(TARGET_EXEC): $(OBJS)
$(CC) $(OBJS) -o $@ $(LDFLAGS)
LD_FLAGS = -L/usr/local/lib/upm -L/usr/lib/rabbitmq
LIBS = -lrabbitmq -lupmc-rn2483 -lupmc-rn2903 -lupmc-utilities
# c source
$(BUILD_DIR)/%.c.o: %.c
$(MKDIR_P) $(dir $@)
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@.o
$(CC) $(LD_FLAGS) $@.o -o $@ $LIBS
.PHONY: clean
clean:
$(RM) -r $(BUILD_DIR)
-include $(DEPS)
MKDIR_P ?= mkdir -p
推荐答案
$(CC) $(LD_FLAGS) $@.o -o $@ $LIBS
# wrong ^^^^^
是错误的. Makefile
变量需要括号:$(LIBS)
,并且您的$LIBS
被理解为$(L)IBS
,并且您没有任何L
变量(因此$LIBS
扩展为IBS
,因为$L
扩展为空)
is wrong. Makefile
variables need parenthesis: $(LIBS)
and your $LIBS
is understood as $(L)IBS
and you don't have any L
variable (so $LIBS
expands to IBS
since $L
expands to nothing)
顺便说一句,您可能已将make --trace
或翻拍与-x
一起使用来发现错误
BTW, you could have used make --trace
or remake with -x
to find that bug
关于已编辑的问题,我相信对于这么小的程序拥有如此复杂的源代码树可能是错误的(通常来说,少于几十万行的小程序在平面源代码树中更容易处理) ,这是一个同时包含*.c
和*.h
源文件的目录.但是,您可能会考虑
Regarding the edited question, I believe that you might be wrong in having such a complex source tree for such a small program (generally speaking, small programs of less than a few dozen thousands lines are simpler to deal in a flat source tree, that is a single directory containing both *.c
and *.h
source files). However, you might consider
INC_DIRS = $(wildcard */include)
这篇关于C Makefile链接器错误-的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!