Saturday, February 19, 2022

[SOLVED] NOTE: a missing vtable usually means the first non-inline virtual member function has no definition

Issue

My system is macOS Big Sur and I have a compilation problem. This is my program:

#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();
}

This is the error when I try 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)

Do you know anything about this problem?


Solution

You are trying to compile C++ code with a C compiler. Just use:

g++ -Wall main.cpp -o my_program


Answered By - Daniel Trugman
Answer Checked By - Marie Seifert (WPSolving Admin)