gpt4 book ai didi

c++ - makefile 编译问题

转载 作者:行者123 更新时间:2023-11-28 06:04:49 26 4
gpt4 key购买 nike

我的 makefile 有点问题当我尝试 make 时出现错误:

no rule to make the target main.o

但我看不到我的错误,实际上它是我几年前制作的模板 Makefile,它是一个 cpp 项目。

(我有另一个错误:/usr/bin/ld: can't find Sources/: file format not know,我想我在通配符方面做错了)

NAME = Pretorian

SRCDIR = ./Sources/
HDDIR = ./Include/

SRCS = $(SRCDIR)$(wildcard *.cpp)
OBJ = $(SRCS:.cpp=.o)

CC = g++

RM = rm -f
ECHO = echo -e

CFLAGS += -W -Wall -Werror -ansi -pedantic
HFLAGS = -I$(HDDIR)
LDFLAGS =

%.o: %.cpp
$(CC) -o $@ -c $< $(CFLAGS)

$(NAME): $(OBJ)
@$(CC) $(CFLAGS) $(HFLAGS) -o $(NAME) $^ $(LDFLAGS)
@$(ECHO) '\033[0;32m> Compiled Without error\033[0m'

all:
$(NAME)

clean:
$(RM) $(OBJ)
@$(ECHO) '\033[0;33m> Directory cleaned\033[0m'

fclean: clean
$(RM) $(NAME)
@$(ECHO) '\033[0;33m> Remove executable\033[0m'

re: fclean all

最佳答案

这似乎对我有用:

SRCS = $(wildcard $(SRCDIR)*.cpp)

关于c++ - makefile 编译问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32606092/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com