今天写了一个makefile文件,没想到各种坑。先记录下来,慢慢修改
1、最开始版本
CC:= g++
TARGET:= threadpool
INCLUDE:= -I./
LIBS:= -lpthread
# C++语言编译参数
CXXFLAGS:= -std=c++11 -g -Wall -D_REENTRANT
# C预处理参数
# CPPFLAGS:=
OBJECTS:= thread_pool.o main.o
$(TARGET):$(OBJECTS)
$(CC) -c $(TARGET) $(OBJECTS) $(LIBS)
# $@表示所有目标集
%.o:%.cpp
$(CC) -c $(CXXFLAGS) $(INCLUDE)$< .o $@
.PHONY:clean
clean:
-rm -f $(OBJECTS) $(TARGET)
错误提示:
g++: error: .o: 没有那个文件或目录
g++: error: thread_pool.o: 没有那个文件或目录g++: fatal error: no input files
compilation terminated.
makefile:15: recipe for target 'thread_pool.o' failed
make: *** [thread_pool.o] Error 1
粗心写错了几处,这是修正后的版本:
CC := g++
TARGET := threadpool
INCLUDE := -I./
LIBS := -lpthread
# C++语言编译参数
CXXFLAGS:= -std=c++11 -g -Wall -D_REENTRANT
# C预处理参数
# CPPFLAGS:=
OBJECTS:= thread_pool.o main.o
$(TARGET):$(OBJECTS)
$(CC) -o $(TARGET) $(OBJECTS) $(LIBS)
# $@表示所有目标集
%.o:%.cpp
$(CC) -c $(CXXFLAGS) $(INCLUDE) $< -o $@
.PHONY:clean
clean:
-rm -f $(OBJECTS) $(TARGET)
2、cannot declare variable ‘taskObj’ to be of abstract type ‘CMyTask’
CMyTask taskObj;
出现这个错一定是子类和父类中的虚函数没有匹配成功,检查函数名字和参数等。而且下面会有错误提示