[Qt-interest] Making a Qt program into a dynamic library

Guido Seifert Wargand at gmx.de
Wed Dec 16 11:50:43 CET 2009


> Strange. A minimal example works for me. See below.
> 
> So the remaining conclusion is that your "plugin" has global variables
> that 
> depend on Qt and are initialized before your main function gets called. 
> Fortunately this is something that you have full control over.

This is extremely strange. Here the very simple plugin I just tried:

MyTest.cpp:

#include <QString>

void start()
{
 QString str;
}

MyTest.pro:

SOURCES += MyTest.cpp

CONFIG += qtcore
CONFIG -= thread
CONFIG += shared

TEMPLATE = lib
MOC_DIR = ./.moc
OBJECTS_DIR = ./.obj

Above results in libMyTest.so.1.0.0
The test program, which loads the lib:

int main(int argc, char *argv[])
{
  void* handle = dlopen("./libMyTest.so.1.0.0", RTLD_LAZY);
  return 0;
}

Result: segfault
Same happens when I comment out the QString.
As I said, having CONFIG += qtcore (or += qt) in .pro file is enough to
ensure the crash. Clearly no global variables on my side.

What Qt version do you use? 

-- 
Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3.5 -
sicherer, schneller und einfacher! http://portal.gmx.net/de/go/atbrowser



More information about the Qt-interest-old mailing list