有时你会发觉,大量的工作时间花在编译错误处理...现在收集些经常出现的错误...

 
c++:
1.undefined reference to `typeinfo for XXXXX(某个类)
  这样的错误很可能该类里存在纯虚函数. 即virtual xx() = 0;
  那么在makefile 里添加
  CFLAGS += -fno-rtti
  CXXFLAGS += -fno-rtti
  即可屏蔽掉这个错误. 
  
  这样的错误也可能是类里的构造函数和析构函数是私有的.即private
  如果有指针变量的数据类型是属于这样的构造类,那么就会出错
  为了屏蔽这样的错误.预编译处理增加...
  -Wno-ctor-dtor-privacy 
  即可屏蔽这样的错误.
  
2.error: invalid use of incomplete type ‘struct BookTextView’
  非法使用不完整的类...即该类没有被声明
 
3.error: invalid initialization of reference of type ‘xxx’ from expression of type ‘yyy’
  从yyy类型转换xxx类型,初始化无效,因为不匹配
 
4.undefined reference to `FBThread::~FBThread()'
   undefined reference to `vtable for FBThread'
  很可能是moc没处理好
 
5.手工编写QT 的moc
-include moc.mk
INCLUDE = $(QTINCLUDE) $(ZINCLUDE) $(EXTERNAL_INCLUDE)
HEADERS = $(wildcard *.h)
SOURCES = $(wildcard *.cpp)
OBJMOC = $(patsubst %.cpp, %.o, $(SRCMOC))
OBJECTS = $(patsubst %.cpp, %.o, $(SOURCES))
 
.SUFFIXES: .cpp .moc.cpp .moc.o .o .h
 
.cpp.o:
@echo -n 'Compiling $@ ...'
@$(CC) -MMD -c $(CFLAGS) $(INCLUDE) $<
@echo ' OK'
 
.h.moc.cpp:
@echo -n 'Generating $@ ...'
@$(MOC) $< -o $@
@echo ' OK'
 
all: $(OBJECTS) $(OBJMOC)
 
clean:
@$(RM) *.o *.moc.cpp *.d
 
-include *.d