make 找不到 make 目标的规则(手动生成 makefile 的新手)

发布于 2024-12-05 17:01:52 字数 2327 浏览 3 评论 0原文

我尝试根据教程构建以下 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

帅气尐潴 2024-12-12 17:01:52

不要将源列为所有源的依赖项。

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.

我偏爱纯白色 2024-12-12 17:01:52

如果没有有关构建环境的大量信息,我无法看到您的 make 到底哪里出了问题,但最好的选择是:

  1. 使用 make -d 来向您展示哪里出了问题。如果不使用隐式规则,make -rd 会更简洁。
  2. 使用 automake 可以完全避免编写 Makefile。

原则上,如果有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:

  1. Use make -d to show you where things went wrong. If you don't use implicit rules, make -rd is more concise.
  2. Use automake to avoid writing a Makefile at all.

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文