Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Undefined reference errors in Windows, working fine in Linux

Undefined reference errors in Windows, working fine in Linux

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jose L. Patino
    wrote on 10 Feb 2020, 18:53 last edited by
    #1

    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?

    Thanks.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 10 Feb 2020, 18:57 last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      J 1 Reply Last reply 10 Feb 2020, 19:38
      4
      • C Offline
        C Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on 10 Feb 2020, 18:59 last edited by
        #3

        You need to mark the functions/classes you want to use outside the library as visible: https://wiki.qt.io/How_to_create_a_library_with_Qt_and_use_it_in_an_application

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        2
        • S SGaist
          10 Feb 2020, 18:57

          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.

          J Offline
          J Offline
          Jose L. Patino
          wrote on 10 Feb 2020, 19:38 last edited by Jose L. Patino 2 Oct 2020, 19:40
          #4

          @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
          {
              ...
          

          by adding CMLIBSHARED_EXPORT:

          class CMLIBSHARED_EXPORT Entity : public QObject
          {
              ...
          

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

          1 Reply Last reply
          1

          1/4

          10 Feb 2020, 18:53

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved