Plugin derived from QGeoServiceProviderFactory gives linker errors
-
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 ¶meters, 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
-
@DuBu
As you say, theQGeoServiceProviderFactory
methods are not markedpure
. So maybe your error could come from not doing a full, clean rebuild, especially if you addedQ_OBJECT
? Btw, your linker error message does not look "complete", would have expected e.g. a line above stating what the error actually is? -
@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.
-
-
-
@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. -
-
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 useqt_import_plugins
, but I don't know how.
But anyway I think my app wants to load a shared library. When I setQT_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!
-