c++ - 注意:缺少 vtable 通常意味着第一个非内联虚拟成员函数没有定义
问题描述
我的系统是 macOS Big Sur,我遇到了编译问题。这是我的程序:
#include <iostream>
#include <sys/ioctl.h>
#include <unistd.h>
class view {
virtual void draw() = 0;
};
class tui : view {
public:
void draw();
};
void tui::draw() {
struct winsize size;
ioctl(STDOUT_FILENO, TIOCGWINSZ, &size);
printf("x = %hu, y = %hu\n", size.ws_row, size.ws_col);
}
int main() {
tui a;
a.draw();
}
这是我尝试时的错误gcc -Wall main.cpp -o my_program
:
Undefined symbols for architecture x86_64:
"vtable for __cxxabiv1::__class_type_info", referenced from:
typeinfo for view in main-c2a1d3.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
"vtable for __cxxabiv1::__si_class_type_info", referenced from:
typeinfo for tui in main-c2a1d3.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
"___cxa_pure_virtual", referenced from:
vtable for view in main-c2a1d3.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
你知道这个问题吗?
解决方案
您正在尝试使用 C 编译器编译 C++ 代码。只需使用:
g++ -Wall main.cpp -o my_program
推荐阅读
- python - 通过交替元素将列表拆分为 2 个列表
- java - Spring MVC - 使用 @WebMvcTest 测试控制器时出现 @EnableGlobalMethodSecurity 错误 404
- shell - 应该如何处理由变量扩展产生的反斜杠?
- swift - 一个新的 NSViewController 的 segue 应该在覆盖整个 Window 的旧的顶部显示新的
- azure - 具有多个终结点的 Azure 机器学习 (AML) Web 服务 REST API
- python - 从字符串设置 qml 模型和属性
- mysql - 如何配置 sequalize & node mysql 以使用新的 aws rds root cert rds-ca-2019
- php - 尝试创建带有 CollectionType 调用另一个 FromType 的复选框时的表单问题(跨实体情况)
- javascript - 如何使用 java 脚本知道 pdf 的尺寸,并对其进行快照以显示在网页上?
- java - Java - 客户端和服务器是否可以通过 IPv4 连接而无需端口转发?