2015-06-22 54 views
0

我編寫了一些C++文件,編譯後使用out make file可以正常工作。但是在使用make文件時會彈出一些錯誤。我的代碼是:未定義引用`vtable for implementation'錯誤

包括目錄下的文件:

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目錄conatins .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) 

後乳寧讓我得到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文件中的任何問題?我認爲問題在於鏈接頭文件。這是鏈接頭文件的正確方法嗎?請幫助我使我的make文件工作。

+0

這是一個很大的文件,審議...您是否已嘗試減少代碼(刪除文件)以檢查可能導致錯誤的原因?它似乎與*多線程*無關,所以我刪除了標籤。 – Wolf

回答

1

我認爲你只是在CFLAGES=-c -Wall

我猜是這樣拼寫錯誤CFLAGS因爲

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

沒有-c選項

+1

噢天啊..這是我的錯誤..工作正常,我也改變了「mv main.o $(OBJ)」到所有代碼...它工作正常..謝謝 – user39320

相關問題