[英]Makefile fails with error no rule to make target
我正在努力创建一个有效的make文件。
我的结构
我的密码
# Define compiler
CC = g++
# Compiler flags
CFLAGS = -g -Wall
# Build target executable
DIR = /src
INCLUDES = ../include
TARGET = main
all: $(TARGET)
$(TARGET): $(TARGET).cpp
cd $(DIR) &
$(CC) $(CFLAGS) -I $(INCLUDES) -o $(TARGET) $(TARGET).cpp
clean:
cd $(DIR) &
$(RM) $(TARGET)
我的错误
make:***没有规则将目标设为main.cpp', needed by
main' main.cpp', needed by
。 停止。
编辑在我的main.cpp内部,这是我的Makefile所在的顶部: #include "pugixml.hpp"
我认为这应该为您工作。
所有路径都相对于Makefile所在的文件夹给出。这意味着需要为源依赖项指定源文件夹。
# Define compiler
CC = g++
# Compiler flags
CFLAGS = -g -Wall
# Build target executable
SRC = src
INCLUDES = include
TARGET = main
all: $(TARGET)
$(TARGET): $(SRC)/$(TARGET).cpp
$(CC) $(CFLAGS) -I $(INCLUDES) -o $@ $^
clean:
$(RM) $(TARGET)
对命令使用制表符(而不是空格)。
$@
解析为目标(本例中为main
)。
$^
解析为所有依赖项(在这种情况下为src/main.cpp
)。
无需cd
进入源文件夹。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.