Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved qApp->addLibraryPath() doesn't work but PATH does (Windows, MinGW)

    Installation and Deployment
    2
    3
    1041
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • dfly
      dfly last edited by

      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!

      1 Reply Last reply Reply Quote 0
      • Chris Kawa
        Chris Kawa Moderators last edited by

        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 before main() is even executed. If the dlls of those libs can't be found your app won't start and won't even get to the addLibraryPath code. Note that QCoreApplication 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.

        1 Reply Last reply Reply Quote 0
        • dfly
          dfly last edited by

          That makes tons of sense, thank you. I hadn't even considered that it would need those libraries just to create the application object, but of course it does. Thanks for your quick reply!

          1 Reply Last reply Reply Quote 0
          • First post
            Last post