4

I got an error saying

undefined reference to 'virtual thunk to myClass::myFunction'

For a library i'm trying to create.

Here's my code :

myClass.cpp :
    #include "myClass.h"
    void myClass::myFunction() {}
    myClass::~myClass() {}

.

myClass.h :
    {inclusion guards}

    #include "myClass_global.h"

    class MY_CLASSSHARED_EXPORT myClass {
        public:
            myClass();
            virtual void myFunction();
            virtual ~myClass();
    };

.

myClass_global.h
    {inclusion guards}

    #include <QtCore/qglobal.h>

    # if degined(MY_CLASS_LIBRARY)
    #    define MY_CLASSSHARED_EXPORT Q_DECL_EXPORT
    # else
    #    define MY_CLASS Q_DECL_IMPORT
    # endif

I'm not really used to making libraries. I'm under QtCreator.

I've found that a "virtual thunk" might be a "function pointer" to something (a destructor ?) that can't be found ...

However, I haven't found anything very clear on the internet ...

  • It's clear you're not posting real code. `define MYCLASS_SHARED_EXPORT Q_DECL_EXPORT`? If you can't reproduce a minimal correct example that reproduces the problem, you're out of luck here. – Luchian Grigore Mar 21 '13 at 16:03
  • That's auto-code from QtCreator ... Where's the problem ? I will edit if there's a problem ... –  Mar 21 '13 at 16:04
  • Gurgh ... seems like the problem is a mismatch configuration version between GCC. I'm trying to compile the library with a more recent version than another library has been compiled with. –  Mar 22 '13 at 08:32

3 Answers3

2

The problem is a mismatch configuration version between GCC.

The library I consumed was compiled with GCC 5.4, but I was using GCC 7.4.

When I use the GCC same as the library to compile my code, this weird linking issue is gone!

Yifei Wu
  • 41
  • 5
2

Maybe it will help somebody in the future.. For me the problem was caused by a declaration of a virtual function in class that derives from the base abstract class (inside .hpp file) but there was no definition of the function in .cpp file.

S.Seba
  • 121
  • 1
  • 11
0

I did notice that the constructor has not been implemented. Could this be causing the issue?

by.axiom
  • 51
  • 3
  • I think it is ... I just misspelled that ... I'm correcting. And I still got that issue ... –  Mar 22 '13 at 08:32