make 找不到 make 目标的规则(手动生成 makefile 的新手)
我尝试根据教程构建以下 makefile。然后我(认为)我添加了必要的源以使其适合我的代码..但它找不到目标。我认为这可能与源的文件夹结构有关,但我无法弄清楚。
SVN_REV=(svnversion -cn | sed -e 's/.*://' -e 's/\([0-9]*\).*/\1/' | grep '[0-9]')
DEBUG_OPTS:=-g -DSVN_REV \
-DDEBUG_MODE \
-UTIME_MODE \
-UREADFROMFILE
CFLAGS:=$(DEBUG_OPTS) -c -Wall
LDFLAGS:=$(DEBUG_OPTS) -lpthread
EXECUTABLE:=fw_board
COMPILER:=arm-linux-gcc
(makefile 继续如下,从 TOPDIR 中可以看到 src 文件位置)
SOURCES:=main_process/main.c \
ezxml/ezxml.c \
info_file_parser/info_file_parser.c \
info_file_parser/array_management.c \
info_file_parser/protocol_file_parser.c \
info_file_parser/sequence_file_parser.c \
info_file_parser/topology_file_parser.c \
seq_exec_module/seq_execution.c \
i2c_device_drivers/pca950x.c \
i2c_device_drivers/ltc2495.c \
i2c_device_drivers/ltc2609.c \
i2c_device_drivers/temperature_uc.c \
i2c_device_drivers/pcf8574.c \
i2c_device_drivers/stepper_motor_control.c \
i2c_device_drivers/test_functions.c \
i2c_device_drivers/stepper_pca.c \
i2c_device_drivers/stepper_atmega.c \
i2c_device_drivers/general_i2c.c \
i2c_device_drivers/zx_mbd_pwr.c \
i2c_device_drivers/virtual_switch_handler.c \
i2c_device_drivers/pressure_sensor_ASDXAV030PG7A5.c \
hashing/ConfigData.c \
hashing/Hash.c \
hashing/LinkedList.c \
init_file_parser/init_file_parser.c \
usb_communication/serial_comm.c \
protocol_parser/protocol_parser.c
BINDIR:=bin
OBJDIR:=.obj
OBJECTS:=$(addprefix $(OBJDIR)/,$(SOURCES:%.c=%.o))
.PHONY: all
all: $(SOURCES) $(EXECUTABLE)
@echo all_start
这是链接阶段
$(EXECUTABLE): $(OBJECTS) | $(BINDIR)
@echo link
$(COMPILER) $(LDFLAGS) $(OBJECTS) -o $(BINDIR)/$@
和编译阶段。但无法找到 main.c,因为您将看到
$(OBJECTS): $(OBJDIR)/%.o : %.c | $(OBJDIR)
@echo compile
$(COMPILER) $(CFLAGS) $< -o $@
$(OBJDIR):
mkdir $(OBJDIR)
$(BINDIR):
mkdir $(BINDIR)
.PHONY: clean
clean:
@echo removing_files
rm -rf $(OBJECTS) $(BINDIR)/$(EXECUTABLE)
运行 make 返回以下内容:
make: *** No rule to make target `main_process/main.c', needed by `all'. Stop.
I have the following makefile that I tried to construct out of a tutorial. Then I (thought) i added the necessary sources in order to fit it for my code.. but it doesn't find the target. I think It may have to do with the folder structure of the sources, but I can't figure it out.
SVN_REV=(svnversion -cn | sed -e 's/.*://' -e 's/\([0-9]*\).*/\1/' | grep '[0-9]')
DEBUG_OPTS:=-g -DSVN_REV \
-DDEBUG_MODE \
-UTIME_MODE \
-UREADFROMFILE
CFLAGS:=$(DEBUG_OPTS) -c -Wall
LDFLAGS:=$(DEBUG_OPTS) -lpthread
EXECUTABLE:=fw_board
COMPILER:=arm-linux-gcc
(makefile cont'd below, there are the src files locations as seen from the TOPDIR)
SOURCES:=main_process/main.c \
ezxml/ezxml.c \
info_file_parser/info_file_parser.c \
info_file_parser/array_management.c \
info_file_parser/protocol_file_parser.c \
info_file_parser/sequence_file_parser.c \
info_file_parser/topology_file_parser.c \
seq_exec_module/seq_execution.c \
i2c_device_drivers/pca950x.c \
i2c_device_drivers/ltc2495.c \
i2c_device_drivers/ltc2609.c \
i2c_device_drivers/temperature_uc.c \
i2c_device_drivers/pcf8574.c \
i2c_device_drivers/stepper_motor_control.c \
i2c_device_drivers/test_functions.c \
i2c_device_drivers/stepper_pca.c \
i2c_device_drivers/stepper_atmega.c \
i2c_device_drivers/general_i2c.c \
i2c_device_drivers/zx_mbd_pwr.c \
i2c_device_drivers/virtual_switch_handler.c \
i2c_device_drivers/pressure_sensor_ASDXAV030PG7A5.c \
hashing/ConfigData.c \
hashing/Hash.c \
hashing/LinkedList.c \
init_file_parser/init_file_parser.c \
usb_communication/serial_comm.c \
protocol_parser/protocol_parser.c
BINDIR:=bin
OBJDIR:=.obj
OBJECTS:=$(addprefix $(OBJDIR)/,$(SOURCES:%.c=%.o))
.PHONY: all
all: $(SOURCES) $(EXECUTABLE)
@echo all_start
this is the linking stage
$(EXECUTABLE): $(OBJECTS) | $(BINDIR)
@echo link
$(COMPILER) $(LDFLAGS) $(OBJECTS) -o $(BINDIR)/$@
and the compilation stage. but main.c can't be located as you'll see
$(OBJECTS): $(OBJDIR)/%.o : %.c | $(OBJDIR)
@echo compile
$(COMPILER) $(CFLAGS) lt; -o $@
$(OBJDIR):
mkdir $(OBJDIR)
$(BINDIR):
mkdir $(BINDIR)
.PHONY: clean
clean:
@echo removing_files
rm -rf $(OBJECTS) $(BINDIR)/$(EXECUTABLE)
running make returns the following:
make: *** No rule to make target `main_process/main.c', needed by `all'. Stop.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不要将源列为所有源的依赖项。
all:取决于 $(EXECUTABLE)。顺便说一句,echo 只会在 $(EXECUTABLE) 构建之后才会得到输出(如果有的话)。
$(EXECUTABLE): 取决于 $(OBJECTS)
我不太确定 $(OBJECTS) 规则的语法在做什么,但不需要对 $(OBJECTS) 有明确的规则。只需让 $(OBJECTS) 列出所有目标文件,然后制定从 C 文件生成它们的规则就足够了。
有了所有这些规则,“all:”无论如何都隐含地依赖于来源。另外,“all:”是一个“虚假”规则,因此每次都会重建所有依赖项。
路径 main_process/main.c 需要相对于包含 makefile 的目录存在。
解决所有这些问题,你就可以开始了。
Don't list the sources as a dependency of all.
all: depends on $(EXECUTABLE). Incidentally, the echo will only get output (if at all) AFTER $(EXECUTABLE) has been built.
$(EXECUTABLE): depends on $(OBJECTS)
I'm not quite sure what the syntax on your $(OBJECTS) rule is doing, but there is no need to have an explicit rule on $(OBJECTS). Just having the $(OBJECTS) list all the object files, and then having a rule to generate them from the C files is sufficient.
With all those rules, "all:" is implictly dependant on the sources anyway. Also, "all:" is a "phony" rule, so will rebuild all dependencies every time anyway.
The path main_process/main.c needs to exist relative to the directory that contains the makefile.
Fix all that and you should be good to go.
如果没有有关构建环境的大量信息,我无法看到您的 make 到底哪里出了问题,但最好的选择是:
原则上,如果有main_process/main.c这样的文件,就应该编译它。您是否尝试过具有完全相同名称的 ls ?
I can't see where exactly your make went wrong without a lot of information about your build environment, but your best bets are:
In principle, if there is such a thing as the file main_process/main.c, it should be compiled. Have you tried an ls with the exact same name?