PDA

View Full Version : QWT integration with static QT build



DizzyMoods
14th October 2011, 14:35
Hello.

I'm working on a small scientific Qt project for experimental data handling data visualization. Since this project is mostly designated for Windows users, I intend to create a statically linked distribution of the final product, so as not to burden the users. I've built Qt statically according to these (http://developer.qt.nokia.com/wiki/How_to_build_a_static_Qt_version_for_Windows_with_ gcc) instructions. I've made some minors changes to the configuration call (for instance, I excluded the Webkit plugin due to some compilation difficulties), but in general the whole build seems to be working fine. I can easily create standalone builds for simple Qt applications (typical executable is about 8-9 MB large). I have also compiled Qwt (with its defaults configuration) and I can run the Qwt examples and I can import Qwt to my own projects. My problem is that I can't seem to combine both the static Qt build and Qwt. I am able to build a Qwt containing project statically and create an executable file, but its execution always leads to an error (A pop-up widow: "Microsoft Visual C++ Runtime Library: This application has requested the Runtime to terminate it an unusual way. Please contact the application's support team for more information", and "Invalid parameter passed to C runtime function." in the output). Note that a default (dynamic ?) build of the same application always succeeds. What might be the problem?

Thanks in advance.

DizzyMoods
16th October 2011, 01:36
I'm bumping this thread once again, since I'm still faced with the same problem. I'll try to be more specific. After my previous atempts I tried to build a static version of QWT (by disabling the "#QWT_CONFIG += QwtDll" option during installation) but I still can't build a static release of a QWT program
Take, for instance, this (http://www.richelbilderbeek.nl/CppQwtExample1.htm) simple example. After a few slight modifications my *.pro file looks like this:


include( C:/qwt-6.0.1/qwt.prf )
QT += core gui
CONFIG += qt
TARGET = CppQwtExample1
TEMPLATE = app
SOURCES += main.cpp
static {
CONFIG += static
DEFINES += STATIC
}

and my main file looks like this:


#include <cmath>
#include <QApplication>
#include <qwt_plot.h>
#include <qwt_plot_curve.h>

int main(int argc, char **argv)
{
QApplication a(argc, argv);
QwtPlot plot(QwtText("CppQwtExample1"));
plot.setGeometry(0,0,640,400);
plot.setAxisScale(QwtPlot::xBottom, 0.0,2.0 * M_PI);
plot.setAxisScale(QwtPlot::yLeft,-1.0,1.0);
QwtPlotCurve sine("Sine");
std::vector<double> xs;
std::vector<double> ys;
for (double x = 0; x < 2.0 * M_PI; x+=(M_PI / 10.0))
{
xs.push_back(x);
ys.push_back(std::sin(x));
}
sine.setSamples(&xs[0],&ys[0],xs.size());
sine.attach(&plot);
plot.show();
return a.exec();
}


I can build it just fine with the usual 4.7.0 release option. A static release, on the other hand, fails. I get a:

:: error: collect2: ld returned 1 exit status
linking error in build issues screen and lots of these kind of errors:

C:/Qwt-6.0.1/lib/libqwt.a(qwt_text.o):qwt_text.cpp:(.text+0x22b): undefined reference to `_imp___ZN4QPenC1EN2Qt8PenStyleE'
C:/Qwt-6.0.1/lib/libqwt.a(qwt_text.o):qwt_text.cpp:(.text+0x245): undefined reference to `_imp___ZNK4QPeneqERKS_'
C:/Qwt-6.0.1/lib/libqwt.a(qwt_text.o):qwt_text.cpp:(.text+0x261): undefined reference to `_imp___ZN6QBrushC1EN2Qt10BrushStyleE'
C:/Qwt-6.0.1/lib/libqwt.a(qwt_text.o):qwt_text.cpp:(.text+0x27b): undefined reference to `_imp___ZNK6QBrusheqERKS_'
C:/Qwt-6.0.1/lib/libqwt.a(qwt_text.o):qwt_text.cpp:(.text+0x28d): undefined reference to `_imp___ZN6QBrushD1Ev'
...
C:/Qwt-6.0.1/lib/libqwt.a(qwt_spline.o):qwt_spline.cpp:(.text$_ZN7Q VectorIdEaSERKS0_[QVector<double>::operator=(QVector<double> const&)]+0x31): undefined reference to `_imp___ZN11QVectorData4freeEPS_i'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [release\CppQwtExample1.exe] Error 1
mingw32-make: *** [release] Error 2
in the compile output. So my question remains - what might be the cause of this problem and what are the possible solutions to it?

Spitfire
18th October 2011, 10:36
Hey,

It seems that you've messed up Qt build but I can't tell what exacly.
I've just build Qt 4.7.4 as static and it works with Qwt without any problem.

I need to recompile it to include gcc (now you need to distribute gcc dll with the binary) and debug libraries.
I'll post how I've done it later, I hope that will help you.

Note Qt 4.6.0 < x > 4.7.0 can't be compiled statically and work with UI widgets according to qt bug database.

Spitfire
18th October 2011, 13:20
Ok, so here's what I've got:

Windows 7 64bit running Qt 4.6.3 (installed, not compiled).

I've downloaded Qt 4.7.4 source, changed two lines in qt-everywhere-opensource-src-4.7.4\mkspecs\win32-g++\qmake.conf to look like that:
QMAKE_CFLAGS_RELEASE = -Os -momit-leaf-frame-pointer
QMAKE_LFLAGS = -static -static-libgcc and compiled whole thing using:
configure -release -nomake examples -nomake demos -no-exceptions -no-rtti -no-qt3support -no-scripttools -no-openssl -no-opengl -no-webkit -no-phonon -no-s60 -no-style-motif -no-style-cde -no-style-cleanlooks -no-style-plastique -no-sql-sqlite -platform win32-g++ -static
mingw32-make
Then coment out line 61 in qwt-6.0.1\qwtconfig.pri and compile it (I've done it using Qt Creator).

In test app just add a QwtPlot object and compile. In your *.pro file you will need to add two lines:
INCLUDEPATH += <path to your qwt>\\qwt-6.0.1\\src
LIBS += -L<path to your qwt>\\qwt-6.0.1c\\lib -lqwtafter that everything should work just fine.

Let me know if it works for you.

DizzyMoods
20th October 2011, 16:22
Thanks a lot for the feedback. I tried to build QT according to your instructions, but I still seem to have the same problem: I can either build a static non-Qwt application or a dynamically linked QWT application :). The errors that appear while trying to build a static application, on the other hand, differ this time (and I actually get about 2000 of them). The build issues screen displays a lot of undefined references (qwt_plot_curve.cpp:-1: error: undefined reference to `_imp___ZN8QPainter4saveEv' etc.), and I get this:


C:/Qwt-6.0.1/lib\libqwt.a(qwt_plot_curve.o):qwt_plot_curve.cpp: (.text+0x48c): undefined reference to `_imp___ZN8QPainter4saveEv'
C:/Qwt-6.0.1/lib\libqwt.a(qwt_plot_curve.o):qwt_plot_curve.cpp: (.text+0x4a4): undefined reference to `_imp___ZN8QPainter6setPenERK4QPen'
C:/Qwt-6.0.1/lib\libqwt.a(qwt_plot_curve.o):qwt_plot_curve.cpp: (.text+0x4e5): undefined reference to `_imp___ZN8QPainter7restoreEv'
C:/Qwt-6.0.1/lib\libqwt.a(qwt_plot_curve.o):qwt_plot_curve.cpp: (.text+0x6f8): undefined reference to `_imp___ZN8QPainter4saveEv'
C:/Qwt-6.0.1/lib\libqwt.a(qwt_plot_curve.o):qwt_plot_curve.cpp: (.text+0x712): undefined reference to `_imp___ZN8QPainter5scaleEd
...
C:/Qwt-6.0.1/lib\libqwt.a(qwt_null_paintdevice.o):qwt_null_pain tdevice.cpp:(.text+0x6e2): undefined reference to `_imp___ZN12QPaintDeviceD2Ev'
C:/Qwt-6.0.1/lib\libqwt.a(qwt_null_paintdevice.o):qwt_null_pain tdevice.cpp:(.text+0x712): undefined reference to `_imp___ZN12QPaintEngineC2E6QFlagsINS_18PaintEngin eFeatureEE'
C:/Qwt-6.0.1/lib\libqwt.a(qwt_null_paintdevice.o):qwt_null_pain tdevice.cpp:(.text$_ZN18QwtNullPaintDevice11PaintE ngineD1Ev[QwtNullPaintDevice::PaintEngine::~PaintEngine()]+0x10): undefined reference to `_imp___ZN12QPaintEngineD2Ev'
C:/Qwt-6.0.1/lib\libqwt.a(qwt_null_paintdevice.o):qwt_null_pain tdevice.cpp:(.text$_ZN18QwtNullPaintDevice11PaintE ngineD0Ev[QwtNullPaintDevice::PaintEngine::~PaintEngine()]+0x15): undefined reference to `_imp___ZN12QPaintEngineD2Ev'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [release\untitlediii.exe] Error 1
mingw32-make: *** [release] Error 2
The process "C:\QtSDK\mingw\bin\mingw32-make.exe" exited with code 2.
Error while building project untitlediii (target: Desktop)
When executing build step 'Make'

in the compile output.

Added after 20 minutes:

OK, I was a bit too hasty with my last reply here, because I, in fact, managed to cope with this linking problem. My main error (on both of my attemps) was that I compiled Qwt with the default qmake.exe and not the one from the static QT build. I know that it's a rather silly error, but I hope that my experience will be useful to others :).

Cheers.

Spitfire
21st October 2011, 13:14
Now I know what I've forgot to mention in the steps above :)