qApp->addLibraryPath() doesn't work but PATH does (Windows, MinGW)
-
Hi everyone. I successfully built Qt5.6 on Windows 10 using MinGW. Wasn't easy, but I fought through it.
I also successfully got a hello world program to run. But I had to set PATH for it to pick up the DLLs, which isn't what I was hoping to do.
I would love to hear if anyone has ideas on why the following fails at runtime:
int main(int argc, char *argv[])
{
QCoreApplication qApp(argc, argv);qApp.addLibraryPath("C:\\Qt\\Qt56\\bin"); qApp.addLibraryPath("C:\\MinGW\\mingw32\\bin"); qDebug() << "Hello world!"; return qApp.exec();
}
but
int main(int argc, char *argv[])
{
QCoreApplication qApp(argc, argv);//qApp.addLibraryPath("C:\\Qt\\Qt56\\bin"); //qApp.addLibraryPath("C:\\MinGW\\mingw32\\bin"); qDebug() << "Hello world!"; return qApp.exec();
}
runs successfully with:
PATH=%PATH%;C:\Qt\Qt56\bin;C:\MinGW\mingw32\bin
It should do the same thing, right?
Obviously I have a workaround, but my goal was to read a file and load those dlls instead of setting the PATH, so this is not ideal for me. First world problems.
Thank you!
-
Hi and welcome.
addLibraryPath
is not for Qt core dlls. It's for (among other things) dynamically loaded libraries e.g. the various plugins. Core libraries are linked at compile time which means they are loaded beforemain()
is even executed. If the dlls of those libs can't be found your app won't start and won't even get to theaddLibraryPath
code. Note thatQCoreApplication
is a class defined in one of these libraries so it needs to be already loaded to be instantiated.The usual deployment on Windows is to copy the needed dlls to the executable directory. Definitely don't rely on PATH or hardcoded absolute paths.