简体   繁体   English

makefile为无法使用的目标文件创建自己的目录

[英]makefile to create own directory for object files not working

I am new to makefiles and want to save all my object files in an own directory. 我是makefile的新手,并希望将所有目标文件保存在自己的目录中。 I googled a lot and came to that solution: 我在Google上搜索了很多,然后得出了该解决方案:

CXX = clang++

# compiler flags
CXXFLAGS = -O3 -Wall -Werror -std=c++11
CFLAGS_SFML = -lsfml-graphics -lsfml-window -lsfml-system
SRCS = getInput.cpp createOutput.cpp main.cpp
OBJDIR = obj
OBJS = $(addprefix $(OBJDIR)/, SRCS:.cpp=.o)

all: program.exe

program.exe: $(OBJS)
    $(CXX) $(CXXFLAGS) -o program.exe $(OBJS) $(CFLAGS_SFML)

$(OBJDIR)/%.o: %.cpp
    $(CXX) $(CXXFLAGS) -c $< -o $@

When I try to run the makefile I get this error: 当我尝试运行生成文件时,出现以下错误:

makefile:12: *** target pattern contains no `%'. Stop.

It seems as this error is quite common and does not tell the detail about what is wrong. 似乎该错误很常见,并且没有告诉您错误的详细信息。 It would be great if someone could help me. 如果有人可以帮助我,那将是很棒的。

Problem with OBJS = $(addprefix $(OBJDIR)/, SRCS:.cpp=.o) OBJS = $(addprefix $(OBJDIR)/, SRCS:.cpp=.o)

Try this one. 试试这个。 First you have to make the obj directory also. 首先,您还必须创建obj目录。

CXX = clang++

# compiler flags
CXXFLAGS = -O3 -Wall -Werror -std=c++11
CFLAGS_SFML = -lsfml-graphics -lsfml-window -lsfml-system
SRCS = main.cpp
OBJDIR = obj
OBJS = $(addprefix $(OBJDIR)/, $(SRCS:.cpp=.o))


all: program.exe

program.exe: $(OBJS)
    $(CXX) $(CXXFLAGS) -o program.exe $(OBJS) $(CFLAGS_SFML)

$(OBJDIR)/%.o: %.cpp
    $(CXX) $(CXXFLAGS) -c $< -o $@

For more information use this . 有关更多信息,请使用this

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM