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. Plugin derived from QGeoServiceProviderFactory gives linker errors
Qt 6.11 is out! See what's new in the release blog

Plugin derived from QGeoServiceProviderFactory gives linker errors

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 5.7k Views 2 Watching
  • 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.
  • DuBuD Offline
    DuBuD Offline
    DuBu
    wrote on last edited by
    #1

    Hi,

    I'm trying to write my first plugin. My plugin is derived from QGeoServiceProviderFactory. I looked at the QGeoServiceProviderFactoryOsm implementation, which I can use in my app without any error. But linking my app with my own factory implementation I get linker errors for the methods from QGeoServiceProviderFactory which I didn't override. But they are not pure virtual methods (they have a definition in QGeoServiceProviderFactory), so I don't need to override them.
    It seems the linker can't find the method definitions of QGeoServiceProviderFactory. But why are the other plugins like QGeoServiceProviderFactoryOsm working, they use the same base class?

    Here's my code and the first linker error:

    #pragma once
    
    #include <QObject>
    #include <QtLocation/QGeoServiceProviderFactory>
    
    class GeoServiceProviderFactoryOsmX : public QObject, public QGeoServiceProviderFactory
    {
        Q_OBJECT
        Q_INTERFACES(QGeoServiceProviderFactory)
        Q_PLUGIN_METADATA(IID "org.qt-project.qt.geoservice.serviceproviderfactory/6.0" FILE
                              "osmx_plugin.json")
    public:
        // QGeoServiceProviderFactory interface
        QGeoRoutingManagerEngine *createRoutingManagerEngine(const QVariantMap &parameters,
                                                             QGeoServiceProvider::Error *error,
                                                             QString *errorString) const;
    };
    
      "QGeoServiceProviderFactory::setQmlEngine(QQmlEngine*)", referenced from:
          vtable for GeoServiceProviderFactoryOsmX in mocs_compilation.cpp.o
    

    I seem to be missing something plugin related.

    Cheers, Stephan

    JonBJ 1 Reply Last reply
    0
    • DuBuD DuBu

      Hi,

      I'm trying to write my first plugin. My plugin is derived from QGeoServiceProviderFactory. I looked at the QGeoServiceProviderFactoryOsm implementation, which I can use in my app without any error. But linking my app with my own factory implementation I get linker errors for the methods from QGeoServiceProviderFactory which I didn't override. But they are not pure virtual methods (they have a definition in QGeoServiceProviderFactory), so I don't need to override them.
      It seems the linker can't find the method definitions of QGeoServiceProviderFactory. But why are the other plugins like QGeoServiceProviderFactoryOsm working, they use the same base class?

      Here's my code and the first linker error:

      #pragma once
      
      #include <QObject>
      #include <QtLocation/QGeoServiceProviderFactory>
      
      class GeoServiceProviderFactoryOsmX : public QObject, public QGeoServiceProviderFactory
      {
          Q_OBJECT
          Q_INTERFACES(QGeoServiceProviderFactory)
          Q_PLUGIN_METADATA(IID "org.qt-project.qt.geoservice.serviceproviderfactory/6.0" FILE
                                "osmx_plugin.json")
      public:
          // QGeoServiceProviderFactory interface
          QGeoRoutingManagerEngine *createRoutingManagerEngine(const QVariantMap &parameters,
                                                               QGeoServiceProvider::Error *error,
                                                               QString *errorString) const;
      };
      
        "QGeoServiceProviderFactory::setQmlEngine(QQmlEngine*)", referenced from:
            vtable for GeoServiceProviderFactoryOsmX in mocs_compilation.cpp.o
      

      I seem to be missing something plugin related.

      Cheers, Stephan

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @DuBu
      As you say, the QGeoServiceProviderFactory methods are not marked pure. So maybe your error could come from not doing a full, clean rebuild, especially if you added Q_OBJECT? Btw, your linker error message does not look "complete", would have expected e.g. a line above stating what the error actually is?

      DuBuD 1 Reply Last reply
      0
      • JonBJ JonB

        @DuBu
        As you say, the QGeoServiceProviderFactory methods are not marked pure. So maybe your error could come from not doing a full, clean rebuild, especially if you added Q_OBJECT? Btw, your linker error message does not look "complete", would have expected e.g. a line above stating what the error actually is?

        DuBuD Offline
        DuBuD Offline
        DuBu
        wrote on last edited by DuBu
        #3

        @JonB I did a full clean rebuild, same error.
        Sorry, I forgot to add the first line of the linker error. So here is the full error message:

        Undefined symbols for architecture arm64:
          "QGeoServiceProviderFactory::setQmlEngine(QQmlEngine*)", referenced from:
              vtable for GeoServiceProviderFactoryOsmX in mocs_compilation.cpp.o
          "QGeoServiceProviderFactory::createPlaceManagerEngine(QMap<QString, QVariant> const&, QGeoServiceProvider::Error*, QString*) const", referenced from:
              vtable for GeoServiceProviderFactoryOsmX in mocs_compilation.cpp.o
          "QGeoServiceProviderFactory::createMappingManagerEngine(QMap<QString, QVariant> const&, QGeoServiceProvider::Error*, QString*) const", referenced from:
              vtable for GeoServiceProviderFactoryOsmX in mocs_compilation.cpp.o
          "QGeoServiceProviderFactory::createRoutingManagerEngine(QMap<QString, QVariant> const&, QGeoServiceProvider::Error*, QString*) const", referenced from:
              GeoServiceProviderFactoryOsmX::createRoutingManagerEngine(QMap<QString, QVariant> const&, QGeoServiceProvider::Error*, QString*) const in geoserviceproviderfactoryosmx.cpp.o
          "QGeoServiceProviderFactory::createGeocodingManagerEngine(QMap<QString, QVariant> const&, QGeoServiceProvider::Error*, QString*) const", referenced from:
              vtable for GeoServiceProviderFactoryOsmX in mocs_compilation.cpp.o
          "typeinfo for QGeoServiceProviderFactory", referenced from:
              typeinfo for GeoServiceProviderFactoryOsmX in mocs_compilation.cpp.o
          "vtable for QGeoServiceProviderFactory", referenced from:
              QGeoServiceProviderFactory::QGeoServiceProviderFactory() in mocs_compilation.cpp.o
           NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
        ld: symbol(s) not found for architecture arm64
        clang++: error: linker command failed with exit code 1 (use -v to see invocation)
        ninja: build stopped: subcommand failed.
        

        And as I wrote, it's my first plugin ever. I think I missed something plugin related. The error sounds like I need to add the cpp file with the definitions for QGeoServiceProviderFactory, but I don't have it. The other plugins derived from that factory class (e.g. QGeoServiceProviderFactoryOsm) work perfectly in my app.

        JonBJ 1 Reply Last reply
        0
        • DuBuD DuBu

          @JonB I did a full clean rebuild, same error.
          Sorry, I forgot to add the first line of the linker error. So here is the full error message:

          Undefined symbols for architecture arm64:
            "QGeoServiceProviderFactory::setQmlEngine(QQmlEngine*)", referenced from:
                vtable for GeoServiceProviderFactoryOsmX in mocs_compilation.cpp.o
            "QGeoServiceProviderFactory::createPlaceManagerEngine(QMap<QString, QVariant> const&, QGeoServiceProvider::Error*, QString*) const", referenced from:
                vtable for GeoServiceProviderFactoryOsmX in mocs_compilation.cpp.o
            "QGeoServiceProviderFactory::createMappingManagerEngine(QMap<QString, QVariant> const&, QGeoServiceProvider::Error*, QString*) const", referenced from:
                vtable for GeoServiceProviderFactoryOsmX in mocs_compilation.cpp.o
            "QGeoServiceProviderFactory::createRoutingManagerEngine(QMap<QString, QVariant> const&, QGeoServiceProvider::Error*, QString*) const", referenced from:
                GeoServiceProviderFactoryOsmX::createRoutingManagerEngine(QMap<QString, QVariant> const&, QGeoServiceProvider::Error*, QString*) const in geoserviceproviderfactoryosmx.cpp.o
            "QGeoServiceProviderFactory::createGeocodingManagerEngine(QMap<QString, QVariant> const&, QGeoServiceProvider::Error*, QString*) const", referenced from:
                vtable for GeoServiceProviderFactoryOsmX in mocs_compilation.cpp.o
            "typeinfo for QGeoServiceProviderFactory", referenced from:
                typeinfo for GeoServiceProviderFactoryOsmX in mocs_compilation.cpp.o
            "vtable for QGeoServiceProviderFactory", referenced from:
                QGeoServiceProviderFactory::QGeoServiceProviderFactory() in mocs_compilation.cpp.o
             NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
          ld: symbol(s) not found for architecture arm64
          clang++: error: linker command failed with exit code 1 (use -v to see invocation)
          ninja: build stopped: subcommand failed.
          

          And as I wrote, it's my first plugin ever. I think I missed something plugin related. The error sounds like I need to add the cpp file with the definitions for QGeoServiceProviderFactory, but I don't have it. The other plugins derived from that factory class (e.g. QGeoServiceProviderFactoryOsm) work perfectly in my app.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @DuBu You doubtless know more than I in this area, but those for architecture arm64 messages don't indicate you are mixing architectures somewhere does it?

          1 Reply Last reply
          0
          • DuBuD Offline
            DuBuD Offline
            DuBu
            wrote on last edited by
            #5

            I think, I'm a step further now. I need to put the source files of the plugin into their own project and Qt Creator provides a template for a plugin project. That compiles and links without any errors. Now I need to find out how to use the plugin in my app.

            SGaistS 1 Reply Last reply
            1
            • DuBuD DuBu has marked this topic as solved on
            • DuBuD DuBu

              I think, I'm a step further now. I need to put the source files of the plugin into their own project and Qt Creator provides a template for a plugin project. That compiles and links without any errors. Now I need to find out how to use the plugin in my app.

              SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @DuBu hi,

              You have the starting point here for plugins location finding.

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

              DuBuD 1 Reply Last reply
              1
              • SGaistS SGaist

                @DuBu hi,

                You have the starting point here for plugins location finding.

                DuBuD Offline
                DuBuD Offline
                DuBu
                wrote on last edited by
                #7

                @SGaist Thanks for the link, but I alrady read that and it didn't make much sense for me cause I don't know anything about how a qt plugin works. The issues I had where cmake related, which is also pretty new for me, cause I only used qmake before. I found out I need to use STATIC in the add_library command. With SHARED I get the mentioned linker errors. Who knows why. I also don't know what the difference between add_library and qt_add_library is. Reading the docs confuses me even more. But anyway it works with both.
                So the inital problem of this thread is solved, but now I need to fix the next ones which are QGeoServiceProviderFactory related and the the docs about how to write my own factory plugin is again not really helpful. Debugging into the Qt framwork to find out why it spits out an error while loading my plugin would be really helpful, but I don't want to open the next can of worms.

                1 Reply Last reply
                0
                • DuBuD DuBu has marked this topic as unsolved on
                • DuBuD Offline
                  DuBuD Offline
                  DuBu
                  wrote on last edited by
                  #8

                  I marked the topic as unsolved again, cause I'm completely stuck. As written above I can link my plugin when I set the type of the library to STATIC. But since I don't know anything about cmake I don't know how to add the static library (.a file on macOS) to my project. I read I should use qt_import_plugins , but I don't know how.
                  But anyway I think my app wants to load a shared library. When I set QT_DEBUG_PLUGINS=1 it tries to read the .a file and sais it's not a valid MACH-O file (wrong magic). But unfortunately I can't figure out how to link my plugin successfully. So I'm back at the start if this topic.

                  Any help is appreciated!

                  1 Reply Last reply
                  0
                  • DuBuD Offline
                    DuBuD Offline
                    DuBu
                    wrote on last edited by DuBu
                    #9

                    Now it works! If I add the Location library to find_package and target_link_libraries, I'm able to build my plugin as a SHARED library and my app loads it as well.

                    1 Reply Last reply
                    1
                    • DuBuD DuBu has marked this topic as solved on

                    • Login

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