未定义的引用'vtable for implementation'错误

时间:2015-06-22 10:07:21

标签: c++ build makefile

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

包含目录文件:

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)

在奔跑之后,我得到了如下的热情:

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文件中的任何问题?我认为问题是链接头文件。这是链接头文件的正确方法吗?请帮我把make文件搞定。

1 个答案:

答案 0 :(得分:1)

我认为你在CFLAGS

中拼错了CFLAGES=-c -Wall

我猜这是因为

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

没有-c选项