这是我的文件夹结构:
这是我的Makefile:
# Define compiler
CC = g++
# Compiler flags
CFLAGS = -g -Wall
# Build target executable
DIR = src
TARGET = main
INCLUDES = include
all: $(TARGET)
$(TARGET): $(TARGET).cpp
$(CC) $(CFLAGS) -I $(INCLUDES) -o $(TARGET) $(TARGET).cpp
clean:
$(RM) $(TARGET)
我对如何将$ DIR变量添加到目标感到困惑,我是否需要在每个$ TARGET实例上执行此操作,并且它的格式如下:
$(DIR)/$(TARGET)
答案 0 :(得分:1)
以下更改可帮助您成功编译。您需要先进入DIR文件夹。所以,用过cd $(DIR)。
# Define compiler
CC = g++
# Compiler flags
CFLAGS = -g -Wall
# Build target executable
DIR = src
TARGET = main
INCLUDES = ../include
all: $(TARGET)
$(TARGET): $(TARGET).cpp
cd $(DIR) &
$(CC) $(CFLAGS) -I $(INCLUDES) -o $(TARGET) $(TARGET).cpp
clean:
cd $(DIR) &
$(RM) $(TARGET)