我有这个Makefile:
TARGET = foobar
CXX = g++
CXXFLAGS = -Wall -I./inc/
LINKER = $(CXX) -o
LFLAGS = -I./inc/
SRCDIR = src
INCDIR = inc
OBJDIR = obj
BINDIR = bin
SOURCES := $(wildcard &(SRCDIR)/*.cpp)
INCLUDES := $(wildcard $(INCDIR)/*.h)
OBJECTS := $(SOURCES:$(SRCDIR)/%.cpp=$(OBJDIR)/%.o)
rm = rm -f
$(info SOURCES [${SOURCES}])
$(info INCLUDES [${SOURCES}])
$(info OBJECTS [${OBJECTS}])
$(BINDIR)/$(TARGET): $(OBJECTS)
@$(LINKER) $@ $(LFLAGS) $(OBJECTS)
@echo "Linking complete!"
$(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.cpp
@$(CXX) $(CXXFLAGS) -c $< -o $@
@echo "Compiled "$<" successfully"
.PHONY: clean
clean:
@$(rm) $(OBJECTS)
@echo "Cleanup complete!"
.PHONE: remove
remove: clean
@$(rm) $(BINDIR)/$(TARGET)
@echo "Exacutable removed!"
我的文件夹结构是:
src/somesources.cpp
inc/somesources.h
obj/
bin/
Makefile
这个makefile与c文件完美配合,但我遇到了c ++问题。有人能说出c和c ++之间的区别以及我错在哪里吗?我得到的输出消息是:
SOURCES []
INCLUDES []
OBJECTS []
g++: fatal error: no input files
compilation terminated.
答案 0 :(得分:4)
更改
SOURCES := $(wildcard &(SRCDIR)/*.cpp)
到
SOURCES := $(wildcard $(SRCDIR)/*.cpp)
另外,
.PHONE: remove
应该是
.PHONY: remove