1
我开始研究一个小项目来实现C++中的todo应用程序。MakeFile只编译一个文件
我写了一个Makefile来编译我的C++文件,但Makefile只编译main.cc而没有其他东西。
这里是我的生成文件
#MakeFile for Building the ToDoList App
# Compile CXX Files
CXX := g++-4.9
CXXFLAGS := -std=c++11
CXXFILES := $(wildcard src/*.cc src/lexer/*.cc)
CXXOBJECTS := $(CXXFILES:.cc=.o)
CXXHEADERS := $(wildcard *.h)
# Link all Object Files
LD := ld
LDFLAGS :=
# Declare Clean and Run as Phony Targets
.PHONY: clean run
# The Final Product will be the To-Do APP
all: TedO.app
# Compile the ToDO APP
TedO.app: $(CXXOBJECTS)
$(LD) $(LDFLAGS) -o build/[email protected] $^
# Run the APP from the Build Folder
run: TedO.app
./build/$^
# Compile the CC files into Object files and place it into the same directory.
%.o: %.cc
$(CXX) $(CXXFLAGS) -o [email protected] $<
# Clean all the Objects
clean: $(CXXOBJECTS)
rm $^
这里是我的目录结构
.
├── Makefile
├── Makefile.swp
├── build
│ ├── tedo
│ └── tedo.txt
├── doc
├── src
│ ├── lexer
│ │ ├── lexer.cc
│ │ └── lexer.h
│ └── main.cc
└── tree.txt
4 directories, 8 files
这里运行,当我从控制台输出使
g++-4.9 -std=c++11 -o src/main.o src/main.cc
Undefined symbols for architecture x86_64:
"lexer::lexer()", referenced from:
_main in ccmWqgIU.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make: *** [src/main.o] Error 1
这是什么;干净的意思是? –
@AswinMohan这只是一种在与目标相同的线上写配方的方法,';'之后的任何内容都是第一个配方。例如'run'可以写成'run:build/TedO.app; $ <'尽管通常限制这种类型的语法与没有先决条件的目标相比更好。 – user657267