Important: Please read the Qt Code of Conduct -

Undefined reference errors in Windows, working fine in Linux

  • Hi there,

    Sorry if this question is too elementary but I am not highly experienced in C++ and I can't find by myself what's going wrong with this issue.

    I have been reading the book "Learn QT 5", by Nicholas Sherriff, and so far I have been doing well and I can recommend it as a nice one to get started in all things Qt and C++, in my own opinion.

    I have been doing everything in Ubuntu Linux 18.04, with g++ 7.4.0 and Qt 5.13.0. As I said, just following the book I never had a single problem, everything always compiled and ran just fine. However, I cloned my Git repo into a Windows 10 system, with g++ 9.2.0 and Qt 5.14.0 and the exact same code does not compile any more, giving me "undefined reference" errors to a bunch of methods of a base class several other classes inherits from.

    The base class bringing those "undefined reference" errors is Entity. So I am having a large amount of errors when I try to subclass or get an instance from it, like for example when I try to build cm-ui I get this error (amongst others):

    address.h 13: undefined reference to cm::data::Entity::~Entity()

    ...which I find weird, because the method is indeed implemented and also I can build cm-lib with no issues at all.

    I would like to remark again: the same code in that repo works perfectly in Ubuntu setup. So I am wondering: is there any critical difference between Windows and Linux I am missing here that makes the project code/setup error in Win?


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Unless you are building your library statically, you have to export the symbol you want to use from your library.

    See here for more details and how to do it using Qt.

  • Lifetime Qt Champion

    You need to mark the functions/classes you want to use outside the library as visible:

  • @SGaist Oh, thank you very much. I see now what my problem was: I forgot to define the CMLIBSHARED_EXPORT symbol in the Entity class.

    Once I did it now everything builds flawlessly. So I fixed the Entity class declaration

    class Entity : public QObject


    class CMLIBSHARED_EXPORT Entity : public QObject

    Thank you again, that was really a killer response :) And thank you @Christian-Ehrlicher too!

Log in to reply