PDA

View Full Version : OpenGL problem on msvc2008 in release



redoctober0
5th February 2009, 21:36
Hi i have a bit of a problem. I want to use opengl in my program. I've added


CONFIG += qt thread warn_off debug_and_release build_all
QT += qt3support opengl


to my .pro file. And i create a simple class derived from QGLWidget


#include <QGLWidget>

class QPaintEvent;

class MyOpenGL : public QGLWidget
{
Q_OBJECT
public:
MyOpenGL(QWidget *parent = 0, QGLWidget *shareWidget = 0);
~MyOpenGL(void);

protected:
void paintEvent(QPaintEvent *event);
};


#include "MyOpenGL.h"
#include <QtGui>
#include <QtOpenGL>

MyOpenGL::MyOpenGL(QWidget *parent, QGLWidget *shareWidget)
: QGLWidget(parent, shareWidget)
{
setFixedSize(200, 200);
setAutoFillBackground(false);
}

MyOpenGL::~MyOpenGL(void)
{
}

void MyOpenGL::paintEvent(QPaintEvent *event)
{
}

Nothing fancy. Now everything works fine in debug mode. However when i switch to release mode, the project compiles and runs to the point where i try to instantiate MyOpenGL class. At that point program crashes with the message from Qt:

"Cannot mix incompatible Qt libraries"

I have only Qt4.3.3 installed on my machine and i develop in msvc2008 on WinXP SP3. I'm quite puzzled by this. Since it runs fine in debug and crashed in release would suggest that there is something fishy with the project setup, but i can't find anything wrong with it. Everything looks ok.

I'll appreciate any thoughts on what could be the cause of this problem.

jacek
5th February 2009, 23:06
Run Dependency Walker (http://www.dependencywalker.com) on your executable and see where is looks for Qt libraries. Maybe it takes QtOpenGL from a different location.

redoctober0
6th February 2009, 16:15
Thanks for the tip jacek!

It turns out that i have MiKTex installed (a Latex program) which comes with its own set of QtCore4.dll and QtGui4.dll and the path to it is written in the PATH env variable. In addition, the path to MiKTeX libs preceded the path to QT's libs in the PATH list. So when it was linking in debug it would look in MiKTeX directory for debug version of QT libs wouldn't find them and move on to the QT directory. But in release mode it would find the libs in the MiKTex directory and load them up and then when it tried to load QtOpenGL4.dll from Qt directory it wouldn't match with core libs.

Now all i did was change the order of the paths in the PATH variable so the QT path is first in the list and everything seems to work just fine.

Just a quick follow up then. Is that the best solution for this problem or there's something more elegant?

So thanks again for the tip.

Cheers.

jacek
6th February 2009, 17:59
Is that the best solution for this problem or there's something more elegant?
This is a well-known problem called "DLL hell". The safest solution is to keep all libraries you need in the same directory as the executable, but of course it ruins the whole concept of shared libraries.