Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

incompatible qt library between app and plugin compiled same way

After compiling a Qt application and a Qt plugin with the same flags (except -shared added for compiling the .dll) there is an error message at execution:

"The plugin 'Z:/bug_pyqt/plugin.dll' uses incompatible Qt library. Expected build key "Windows mingw release full-config", got "Windows mingw debug full-config""

Why this error message if both the main application and the plugin were compiled with the same flags?

They were compiled with mingw32-g++ on windows XP under cygwin with a hand-made makefile. Compiling the main application with option "-g" (and plugin still without) makes things "work" and the error message disappear but what is the rationale?

File main.cpp to compile into a.out:

#include <QCoreApplication>
#include <QPluginLoader>
#include <QDebug>

int main(int argc, char **argv)
{
        QCoreApplication app(argc, argv);

        QPluginLoader loader("plugin.dll");
        loader.setLoadHints(QLibrary::ResolveAllSymbolsHint | QLibrary::ExportExternalSymbolsHint);
        loader.load();
        if(!loader.isLoaded()) {
                qDebug() << loader.errorString();
                exit(1);
        }
        (void)loader.instance();

        return app.exec();
}

File plugin.h:

#ifndef PLUGIN_H
#define PLUGIN_H

#include <QObject>

class Plugin : public QObject
{
        Q_OBJECT
public:
        Plugin();
        ~Plugin();

};

#endif

File plugin.cpp to compile into plugin.dll:

#include "plugin.h"

#include <QtPlugin>

Q_EXPORT_PLUGIN2(Plugin, Plugin)

Plugin::Plugin() { }

Plugin::~Plugin() { }

File Makefile:

MOC=/cygdrive/c/Qt/4.8.4/bin/moc
GCC=/cygdrive/c/MinGW/bin/mingw32-g++.exe
FLAGS=-Ic:/Qt/4.8.4/include -Ic:/Qt/4.8.4/include/QtCore -Lc:/Qt/4.8.4/lib -Lc:/Qt/4.8.4/bin -lQtCore4
LIBFLAGS=-shared

all:
        $(MOC) plugin.h > plugin_moc.cpp
        $(GCC) -o a.out main.cpp $(FLAGS)
        $(GCC) -o plugin.dll $(LIBFLAGS) plugin_moc.cpp plugin.cpp $(FLAGS)
like image 544
user2179288 Avatar asked Sep 05 '25 03:09

user2179288


1 Answers

After investigation, here is a half answer

First off, the "build key" that is mentionned in the error message in defined as macro QT_BUILD_KEY in file QtCore/qconfig.h.

Here is a relevant extract of this file:

#if defined(__SYMBIAN32__)
# define QT_BUILD_KEY "Symbian full-config"
#else
# if !defined(QT_NO_DEBUG)
#  if (defined(WIN64) || defined(_WIN64) || defined(__WIN64__))
#   define QT_BUILD_KEY "Windows x64 mingw debug full-config"
#  else
#   define QT_BUILD_KEY "Windows mingw debug full-config"
#  endif
# else
#  if (defined(WIN64) || defined(_WIN64) || defined(__WIN64__))
#   define QT_BUILD_KEY "Windows x64 mingw release full-config"
#  else
#   define QT_BUILD_KEY "Windows mingw release full-config"
#  endif
# endif
#endif

From this we understand that we can force the build type of the plugin to be "release" by defining the macro QT_NO_DEBUG.

Adding "-DQT_NO_DEBUG" on the compile command for the plugin solves the issue.

This still does not explain why by default Qt_BUILD_KEY (or QT_NO_DEBUG) is different between the main app and the plugin.

like image 61
user2179288 Avatar answered Sep 07 '25 23:09

user2179288