incompatible qt library between app and plugin compiled same way - qt

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)

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.

Related

Using DLL's in Qt: undefined reference

I want to use an SDK I got for using a scanner. I'm using Qt 5.3 with MingW32 (on Windows 7).
The very first test I wanted to build should just print the SDK version.
Here is my project file
QT += core
QT -= gui
TARGET = Kojak1
CONFIG += console
CONFIG -= app_bundle
KOJAKDIR = "C:/Program Files/Integrated Biometrics/IBScanUltimateSDK_x64"
TEMPLATE = app
INCLUDEPATH += $$KOJAKDIR/Include
SOURCES += main.cpp
LIBS +=-L$$KOJAKDIR/lib/ -lIBScanUltimate
and here is the source code
#include <QCoreApplication>
#include "stdio.h"
#include <windows.h>
#include "IBScanUltimateApi.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
IBSU_SdkVersion sdk_version;
IBSU_GetSDKVersion(&sdk_version);
printf("%s %s",sdk_version.File,sdk_version.Product);
return a.exec();
}
Unforturnately I get the message
D:\devt\QTProjects\Kojak1\main.cpp:10: error: undefined reference to `IBSU_GetSDKVersion#4'
when trying to compile the program.
My lib directory does contain IBScanUltimate.lib and IBScanUltimate.dll.

A new Qt widget application will not compile

I am relatively new to Qt and was going through many tutorials. Everything was fine. All scripts compiled and ran.
Then, at some point, I am getting the error for even a new Qt widget application created with Qt Creator 4.3.1:
C:\ \Documents\111\main.cpp:-1: In function 'int qMain(int, char**)':
C:\ \Documents\111\main.cpp:6: error: variable 'QApplication a' has initializer but incomplete type
QApplication a(argc, argv);
^
C:\ \Documents\111\main.cpp:11: warning: control reaches end of non-void function [-Wreturn-type]
}
^
I am not sure what happened, yet seems like some setups were messed up.
QApplication is included, and not missing in the script.
111.pro
# Project created by QtCreator 2018-02-23T01:36:28
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = 111
TEMPLATE = app
DEFINES += QT_DEPRECATED_WARNINGS
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h
FORMS += \
mainwindow.ui
main.cpp
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
mainview.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
It seems to me that this issue appeared after trying to run qt5.6_src.zip examples from https://en.ids-imaging.com/open-source.html.
Without completed code, I guess you need to add #include <QApplication> to main.cpp
The error message told you what is missing.
According to Qt's docs, the constructor's signature is QApplication(int &argc, char **argv).
Therefore, if you inherit from QApplication then the subclass's constructor must pass argc by reference. From your description, it appears that the constructor of your subclass is actually passing argc by value (i.e., int qMain(int, char**) ). That will cause some problems.
The issue is fixed by deleting the Qt folder and QtCreator folder in the <drive>:\Users\<username>\AppData\Roaming\QtProject and <drive>:\Users\<username>\AppData\Roaming\Qt. It stored incorrect settings, which I somehow setup by running open source scripts. For more information visit Where does QtCreator save its settings?.

Boost in Qt: Installation and Symbol(s) not found for architectures x86_64

I am back to Qt and C++ programming after a year break. I am trying to install boost library into Qt on Mac (10.9.4) and I am completely confused. This is what I did:
I installed boost using homebrew.
I see that hpp files are installed here:
/usr/local/Cellar/boost/1.55.0_2/include/boost
and libraries here:
/usr/local/Cellar/boost/1.55.0_2/lib
Now I start a new Qt console project.
the project file:
QT += core
QT -= gui
TARGET = testQt
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += /usr/local/Cellar/boost/1.55.0_2
And the main file:
#include <QCoreApplication>
#include <QtCore>
#include <iostream>
#include <QDebug>
#include <boost/regex.hpp>
using namespace std;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
std::string line;
boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" );
while (std::cin)
{
std::getline(std::cin, line);
boost::smatch matches;
if (boost::regex_match(line, matches, pat))
std::cout << matches[2] << std::endl;
}
return a.exec();
}
Not compiling. Issues:
Symbol(s) not found for architectures x86_64
linker command failed with exist code 1
Since I am absolutely noob with boost, did I do it right? If yes, why is it not compiling?
Thanks a lot!
You need to link with boost too!
LIBS += -L/usr/local/Cellar/boost/1.55.0_2/lib -lboost

Why am I getting "undefined reference to vtable..." errors when linking this Qt 5.0 application?

I've got a relatively simple Qt 5.0 project that uses CMake 2.8.9:
CMakeLists.txt:
cmake_minimum_required(VERSION 2.8.9)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
project(hello-world)
find_package(Qt5Widgets REQUIRED)
qt5_wrap_ui(hello-world_UI MainWindow.ui)
add_executable(hello-world MainWindow.cpp main.cpp ${hello-world_UI})
qt5_use_modules(hello-world Widgets)
MainWindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow();
virtual ~MainWindow();
private:
Ui::MainWindow * const ui;
};
#endif // CMAINWINDOW_H
MainWindow.cpp:
#include "MainWindow.h"
#include "ui_MainWindow.h"
MainWindow::MainWindow()
: ui(new Ui::MainWindow)
{
}
MainWindow::~MainWindow()
{
delete ui;
}
main.cpp:
#include <QApplication>
#include "MainWindow.h"
int main(int argc, char * argv[])
{
QApplication app(argc, argv);
MainWindow win;
win.show();
return app.exec();
}
The project also includes a .ui file created with Qt Creator 2.6.1 (MainWindow.ui).
When I attempt to build the file with g++ on Linux, I receive the following errors:
CMakeFiles/hello-world.dir/MainWindow.cpp.o: In function `MainWindow::MainWindow()':
MainWindow.cpp:(.text+0x3b): undefined reference to `vtable for MainWindow'
MainWindow.cpp:(.text+0x4d): undefined reference to `vtable for MainWindow'
CMakeFiles/hello-world.dir/MainWindow.cpp.o: In function `MainWindow::~MainWindow()':
MainWindow.cpp:(.text+0xaf): undefined reference to `vtable for MainWindow'
MainWindow.cpp:(.text+0xc1): undefined reference to `vtable for MainWindow'
collect2: error: ld returned 1 exit status
What could possibly be causing this sort of error? I recently switched to CMake from qmake and I never remember running into this much trouble getting a trivial example to compile. What am I doing wrong?
Edit: here is the command being used to link everything:
/usr/bin/c++ CMakeFiles/hello-world.dir/MainWindow.cpp.o
CMakeFiles/hello-world.dir/main.cpp.o -o hello-world -rdynamic
/usr/local/Qt-5.0.0/lib/libQt5Widgets.so.5.0.0
/usr/local/Qt-5.0.0/lib/libQt5Gui.so.5.0.0
/usr/local/Qt-5.0.0/lib/libQt5Core.so.5.0.0
-Wl,-rpath,/usr/local/Qt-5.0.0/lib
Turns out I forgot:
set(CMAKE_AUTOMOC ON)
At the top of the CMakeLists.txt file.
I struggled with this for a long time using all the hints published here:
http://doc.qt.io/qt-5/cmake-manual.html
And here
https://www.kdab.com/using-cmake-with-qt-5/
What I had to do was specify things in the right order. For example, the following is the top of my CMakeLists.txt. Note that the two CMAKE set directives come before add_executable. Once I did this, I was able to link without undefined symbols and vtable references. I just thought I'd post this for the benefit of others.
cmake_minimum_required (VERSION 2.8)
set (CMAKE_AUTOMOC ON)
set (CMAKE_INCLUDE_CURRENT_DIR ON)
add_executable(FHSpectrumSensor wideband_seq_spectrum_sensor.cpp sensor.cpp gui.cpp ${gui_SRC})
Later in the CMakeLists.txt I have the following:
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Charts REQUIRED)
find_package(Qt5Core REQUIRED)
qt5_use_modules(FHSpectrumSensor Widgets Charts)
qt5_wrap_cpp(gui_SRC gui.h gui.cpp)
That did the trick.
I also ran into this problem yesterday and the above mentioned answers did't help. I already used set (CMAKE_AUTOMOC ON) and also qt5_wrap_cpp.
I tried to remember what I did, because I had a working version but it stopped working after "some" changes. I finally remembered that I tried to split the include files into a separate directory hierarchy. After reverting that and putting the include files back into the CMakeLists.txt it worked again. I sure don't know why, and I would like to know what went wrong, but I settled now for keeping the includes near the cpp files.
set(SOURCES
buffer.h
ITVSet.h
MainWindow.h
MainWindow.cpp
TVSet.h
TVSet.cpp
)

QT Plugin with CMake

Greetings all,
I am trying to implement a QT Plugin with CMake. But this "Q_EXPORT_PLUGIN2" directive stops my class from compiling. I can compile the plugin if I commented this out,but it won't work as a plugin if I do so.
QT doc says:
Q_EXPORT_PLUGIN2 ( PluginName, ClassName )
The value of PluginName should
correspond to the TARGET specified in
the plugin's project file
What about in CMake case? What should be the value for 'PluginName'?
Here is my Plugin Interface :
#ifndef RZPLUGIN3DVIEWERFACTORY_H_
#define RZPLUGIN3DVIEWERFACTORY_H_
#include <QObject>
#include "plugin/IRzPluginFactory.h"
class RzPlugin3DViewerFactory :public QObject,public IRzPluginFactory{
Q_OBJECT
Q_INTERFACES(IRzPluginFactory)
private:
QString uid;
public:
RzPlugin3DViewerFactory();
virtual ~RzPlugin3DViewerFactory();
IRzPlugin* createPluginInstance();
IRzPluginContext* createPluginContextInstance();
QString & getPluginUID();
};
#endif /* RZPLUGIN3DVIEWERFACTORY_H_ */
And implementation
#include "RzPlugin3DViewerFactory.h"
#include "RzPlugin3DViewer.h"
RzPlugin3DViewerFactory::RzPlugin3DViewerFactory() {
uid.append("RzPlugin3DView");
}
RzPlugin3DViewerFactory::~RzPlugin3DViewerFactory() {
// TODO Auto-generated destructor stub
}
IRzPlugin* RzPlugin3DViewerFactory::createPluginInstance(){
RzPlugin3DViewer *p=new RzPlugin3DViewer;
return p;
}
IRzPluginContext* RzPlugin3DViewerFactory::createPluginContextInstance()
{
return NULL;
}
QString & RzPlugin3DViewerFactory::getPluginUID()
{
return uid;
}
Q_EXPORT_PLUGIN2(pnp_extrafilters, RzPlugin3DViewerFactory)
Error Message is :
[ 12%] Building CXX object
CMakeFiles/RzDL3DView.dir/RzPlugin3DViewerFactory.cpp
.obj
C:\svn\osaka3d\trunk\osaka3d\rinzo-platform\src\dlplugins\threedviewer\RzPlugin3
DViewerFactory.cpp:36: error: expected
constructor, destructor, or type
conversi on before '(' token make[2]:
*** [CMakeFiles/RzDL3DView.dir/RzPlugin3DViewerFactory.cpp.obj]
Error 1
make[1]: *
[CMakeFiles/RzDL3DView.dir/all] Error
2 make: * [all] Error 2
Ok , I fixed the problem by giving the project name specified in Cmake file.
PROJECT (RinzoDLPlugin3DViewer CXX C)
So,now in CPP file its
Q_EXPORT_PLUGIN2(RinzoDLPlugin3DViewer , RzPlugin3DViewerFactory)
and included qpluginh.h
#include <qplugin.h>
I think the macro should be Q_EXPORT_PLUGIN2(pnp_rzplugin3dviewerfactory, RzPlugin3DViewerFactory) or whatever you have listed as the target name in the .pro file. In fact, the "pnp" part stands for "Plug & Paint" which is the Qt demo program for writing plugins :)
Edit:
Since I misunderstood how CMake works, this information isn't really relevant to the OP. I did do a quick search however and turned up this discussion of Qt, plugins and CMake. I hope there is some useful info there.
http://lists.trolltech.com/qt-interest/2007-05/msg00506.html

Resources