未定义对“用于实现的 vtable”错误的引用

undefined reference to `vtable for implementation' error

我写了一些 c++ 文件,在使用 out make 文件编译后它工作正常。但是在使用 make file 时会弹出一些错误。我的代码是:

包括目录文件:

application.h

#ifndef APPLICATION_H
#define APPLICATION_H

#include "employee.h"
#include "employee_data.h"
#include "employee.h"  

...some defintions here...

#endif 

employee.h

#ifndef EMPLOYEE_H
#define EMPLOYEE_H

#include "employee_data.h"  

#endif

employee_data.h

#ifndef EMPLOYEE_DATA_H
#define EMPLOYEE_DATA_H

typedef struct
{
 int    emp_id;     

 char   *name,
        *dept,
        *book,
        *time;  

 }employeedata;

 ...some codes here...
#endif

library.h

#ifndef LIBRARY_H
#define LIBRARY_H

#include "employee_data.h"
#include "application.h"
using namespace std;

class Library
{

public:

virtual int addE() = 0;
virtual int  deleteE() = 0; 
virtual int issue() = 0 ;
virtual int returnB() = 0; 
virtual int employee() = 0;

};

class implementation : public Library
{

private:

employeedata *emp; /*structure object*/

public:

int addE();
int deleteE();
int issue();
int returnB();
int employee();

};

#endif

main.h

#ifndef MAIN_H 
#define MAIN_H

#include "library.h"

class message
{
  public:

   void errormessage(int);
 }; 

#endif

和我的 src 目录包含 .cpp 文件。它包括

main.cpp

 #include "main.h"
 #include "library.h" 
 #include "employee_data.h" 
 #include "application.h"

 int main()
 {
  message msg;
   /* codes here..../*
 }

library_function.cpp

 #include "library.h"
 #include "employee.h"
 #include "main.h"
 #include "application.h"
 #include "employee_data.h"

 int implementation :: addE() 
 {

 }

 etc..

error_function.cpp

  #include "main.h"

  void message :: errormessage(int errno)
  {

  }

employee_functions.cpp

  #include "employee.h"
  #include "main.h"
  ..some code...

display.cpp

  #include "employee_data.h"
  #include "application.h"
  ..some code..

thread.cpp

  #include "employee.h"
  #include "application.h"

   ...some code..

我的 make 文件是:

CC=g++
FLAGS=-o
CFLAGES=-c -Wall
THREAD=-lpthread


INCLUDE=../include/
SRC=../src/
OBJ=../obj/
OUTPUT=../bin/


$(OUTPUT)vkp:$(OBJ)main.o $(OBJ)library_functions.o $(OBJ)employee_functions.o $(OBJ)display.o $(OBJ)error_function.o $(OBJ)thread.o
    $(CC) $(FLAGS) vkp $(OBJ)main.o $(OBJ)library_functions.o $(OBJ)employee_functions.o $(OBJ)display.o $(OBJ)error_function.o $(OBJ)thread.o $(THREAD)
    mv vkp $(OUTPUT)

$(OBJ)main.o:$(SRC)main.cpp $(INCLUDE)main.h $(INCLUDE)employee_data.h $(INCLUDE)application.h
    $(CC) $(CFLAGS) $(SRC)main.cpp -I $(INCLUDE)
    mv main.o $(OBJ)

$(OBJ)library_functions.o:$(SRC)library_functions.cpp $(INCLUDE)library.h $(INCLUDE)employee.h $(INCLUDE)main.h $(INCLUDE)application.h $(INCLUDE)employee_data.h
    $(CC) $(CFLAGS) $(SRC)library_functions.cpp -I $(INCLUDE)
    mv main.o $(OBJ)

$(OBJ)employee_functions.o:$(SRC)employee_functions.cpp $(INCLUDE)employee.h $(INCLUDE)main.h
    $(CC) $(CFLAGS) $(SRC)employee_functions.cpp -I $(INCLUDE)
    mv main.o $(OBJ)                

$(OBJ)display.o:$(SRC)display.cpp $(INCLUDE)employee_data.h $(INCLUDE)application.h
    $(CC) $(CFLAGS) $(SRC)display.cpp -I $(INCLUDE)
    mv main.o $(OBJ)

$(OBJ)error_function.o :$(SRC)error_function.cpp $(INCLUDE)main.h
    $(CC) $(CFLAGS) $(SRC)error_function.cpp -I $(INCLUDE)
    mv main.o $(OBJ)

$(OBJ)thread.o:$(SRC)thread.cpp $(INCLUDE)employee.h $(INCLUDE)application.h
    $(CC) $(CFLAGS) $(SRC)thread.cpp -I $(INCLUDE)
    mv main.o $(OBJ)

运行 make 后我得到了 eroor:

g++  ../src/main.cpp -I ../include/
/tmp/cc09snhj.o: In function `main':
main.cpp:(.text+0x568): undefined reference to `message::errormessage(int)'
main.cpp:(.text+0x5fb): undefined reference to `message::errormessage(int)'
main.cpp:(.text+0x6c5): undefined reference to `message::errormessage(int)'
main.cpp:(.text+0x758): undefined reference to `message::errormessage(int)'
main.cpp:(.text+0x7f3): undefined reference to `message::errormessage(int)'
/tmp/cc09snhj.o: In function `implementation::implementation()':
main.cpp:(.text._ZN14implementationC2Ev[_ZN14implementationC5Ev]+0x1f): undefined reference to `vtable for implementation'
collect2: ld returned 1 exit status
make: *** [../obj/main.o] Error 1

我的代码有什么问题? make 文件有问题吗?我认为问题是 linking 头文件。这是 link 头文件的正确方法吗?请帮助我使我的 make 文件正常工作。

我想你只是在 CFLAGES=-c -Wall

中拼错了 CFLAGS

我猜是因为

g++  ../src/main.cpp -I ../include/

没有-c选项