gpt4 book ai didi

c++ - 未定义对 `vtable for implementation' 错误的引用

转载 作者:行者123 更新时间:2023-11-28 06:12:30 25 4
gpt4 key购买 nike

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

包含目录文件:

应用程序.h

#ifndef APPLICATION_H
#define APPLICATION_H

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

...some defintions here...

#endif

员工.h

#ifndef EMPLOYEE_H
#define EMPLOYEE_H

#include "employee_data.h"

#endif

员工数据.h

#ifndef EMPLOYEE_DATA_H
#define EMPLOYEE_DATA_H

typedef struct
{
int emp_id;

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

}employeedata;

...some codes here...
#endif

库.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

主要.h

#ifndef MAIN_H 
#define MAIN_H

#include "library.h"

class message
{
public:

void errormessage(int);
};

#endif

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

主要.cpp

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

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

库函数.cpp

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

int implementation :: addE()
{

}

etc..

错误函数.cpp

  #include "main.h"

void message :: errormessage(int errno)
{

}

employee_functions.cpp

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

显示.cpp

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

线程.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 文件有问题吗?我认为问题在于链接头文件。这是链接头文件的正确方法吗?请帮助我使我的 make 文件正常工作。

最佳答案

我认为你只是在 CFLAGES=-c -Wall 中拼错了 CFLAGS

我猜是因为

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

没有-c选项

关于c++ - 未定义对 `vtable for implementation' 错误的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30977213/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com