Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Load shared library: The specified module could not be found
Forum Updated to NodeBB v4.3 + New Features

Load shared library: The specified module could not be found

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 4 Posters 2.5k Views 3 Watching
  • 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.
  • F Offline
    F Offline
    fem_dev
    wrote on last edited by
    #1

    I'm developing a C++ cross-platform application and a shared library to be loaded in this main application.

    Both projects compile and run Ok in Ubuntu 20.04 and Mac OSX Catalina. All good!

    In Windows environment, I compile both projects without errors or warnings.

    But, when I open my main app and try to load the shared library I got this run-time error:

    Cannot load library C:\Users\VM\Desktop\build-lobular-bearing-plugin-Qt6-Debug\libLobular-Bearing-Plugin.dll: The specified module could not be found .:
    

    1 - Why this is happen in Windows-only environment?
    2 - How can I fix it?

    Obs.: To load the shared library, I'm using the QLibrary class.

    • Windows 10 x64
    • Qt 6.0.1
    • Qt Creator IDE 4.14.0
    1 Reply Last reply
    0
    • F fem_dev

      @mrjj I found where is the problem, but I don't know how to solve it.

      Answer your questions:
      a) No...I'am always running the main app using Qt Creator IDE
      b) As you can see below, I think that it another problem...

      The problem is only one CMakeLists.txt line.
      I'm using a library called json-fortran, that I compilled and installed in my Windows 10 system.

      When I compile the shared library using this first line below, it works great and my main app can load this shared library without any error.

      TARGET_LINK_DIRECTORIES(${PROJECT_NAME} PUBLIC "C:/Users/VM/Downloads/json-fortran/build/lib")
      

      As you can see, I cloned the repo in my Downloads folder...but I also installed the library files in my Program Files folder using: make install.
      All the files are there too.

      BUT, if I switch this line to:

      TARGET_LINK_DIRECTORIES(${PROJECT_NAME} PUBLIC "C:/Program Files (x86)/jsonfortran-gnu-8.2.1/lib")
      

      The shared library project compiles Ok, no errors too. But when my main app tries to load it, I got this run-time error:

      Cannot load library C:\Users\VM\Desktop\build-lobular-bearing-plugin-Qt6-Debug\libLobular-Bearing-Plugin.dll: 
      The specified module could not be found .:
      

      In both cases I got a clean and no error/warning compilation.

      Could you help me?

      Thank you,

      UPDATE 1

      I already tried to include back slashs in the path to skip spaces...but doesn't work too...

      UPDATE 2

      This problem only occurs in Windows environment

      UPDATE 3

      I found a parcial solution:
      In the installed library folder, I have 2 files: libjsonfortran.a and libjsonfortran.dll.a
      If I delete the dll version...the shared library compilation get the .a static file and works good.

      So, How can I instruct the CMake to use always the static version only?

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #5

      @fem_dev said in Load shared library: The specified module could not be found:

      a) No...I'am always running the main app using Qt Creator IDE

      your problem is that the dependency library (libjsonfortran.dll) cannot be found when you load "libLobular-Bearing-Plugin.dll" with QLIbrary. This is done by the OS which looks in certain paths for libaries.
      So either put the dll file next to your exe (which is in this case in QtCreators build folder) or update the PATH variable (can be done in the PROJECTS tab -> Run settings in QtCreator) with the folder containing the dll.
      When you release your exe you should anyway bundle the dependency libraries - probably next to the exe - afterall.

      Also i assume you are using mingw as compiler? If so you should be able to point to the .a file explicitly in the linking definition. (To choose between static and dynamic version of the lib)

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      4
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi
        this is when you run standalone?
        Did you check it has the compiler runtime included in the deplyment folder ?

        F 1 Reply Last reply
        0
        • mrjjM mrjj

          Hi
          this is when you run standalone?
          Did you check it has the compiler runtime included in the deplyment folder ?

          F Offline
          F Offline
          fem_dev
          wrote on last edited by fem_dev
          #3

          @mrjj I found where is the problem, but I don't know how to solve it.

          Answer your questions:
          a) No...I'am always running the main app using Qt Creator IDE
          b) As you can see below, I think that it another problem...

          The problem is only one CMakeLists.txt line.
          I'm using a library called json-fortran, that I compilled and installed in my Windows 10 system.

          When I compile the shared library using this first line below, it works great and my main app can load this shared library without any error.

          TARGET_LINK_DIRECTORIES(${PROJECT_NAME} PUBLIC "C:/Users/VM/Downloads/json-fortran/build/lib")
          

          As you can see, I cloned the repo in my Downloads folder...but I also installed the library files in my Program Files folder using: make install.
          All the files are there too.

          BUT, if I switch this line to:

          TARGET_LINK_DIRECTORIES(${PROJECT_NAME} PUBLIC "C:/Program Files (x86)/jsonfortran-gnu-8.2.1/lib")
          

          The shared library project compiles Ok, no errors too. But when my main app tries to load it, I got this run-time error:

          Cannot load library C:\Users\VM\Desktop\build-lobular-bearing-plugin-Qt6-Debug\libLobular-Bearing-Plugin.dll: 
          The specified module could not be found .:
          

          In both cases I got a clean and no error/warning compilation.

          Could you help me?

          Thank you,

          UPDATE 1

          I already tried to include back slashs in the path to skip spaces...but doesn't work too...

          UPDATE 2

          This problem only occurs in Windows environment

          UPDATE 3

          I found a parcial solution:
          In the installed library folder, I have 2 files: libjsonfortran.a and libjsonfortran.dll.a
          If I delete the dll version...the shared library compilation get the .a static file and works good.

          So, How can I instruct the CMake to use always the static version only?

          raven-worxR 1 Reply Last reply
          1
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #4

            Hi,

            This cmake thread might help.

            Or the quick and dirty is to install the static and shared libraries in separate folders.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            2
            • F fem_dev

              @mrjj I found where is the problem, but I don't know how to solve it.

              Answer your questions:
              a) No...I'am always running the main app using Qt Creator IDE
              b) As you can see below, I think that it another problem...

              The problem is only one CMakeLists.txt line.
              I'm using a library called json-fortran, that I compilled and installed in my Windows 10 system.

              When I compile the shared library using this first line below, it works great and my main app can load this shared library without any error.

              TARGET_LINK_DIRECTORIES(${PROJECT_NAME} PUBLIC "C:/Users/VM/Downloads/json-fortran/build/lib")
              

              As you can see, I cloned the repo in my Downloads folder...but I also installed the library files in my Program Files folder using: make install.
              All the files are there too.

              BUT, if I switch this line to:

              TARGET_LINK_DIRECTORIES(${PROJECT_NAME} PUBLIC "C:/Program Files (x86)/jsonfortran-gnu-8.2.1/lib")
              

              The shared library project compiles Ok, no errors too. But when my main app tries to load it, I got this run-time error:

              Cannot load library C:\Users\VM\Desktop\build-lobular-bearing-plugin-Qt6-Debug\libLobular-Bearing-Plugin.dll: 
              The specified module could not be found .:
              

              In both cases I got a clean and no error/warning compilation.

              Could you help me?

              Thank you,

              UPDATE 1

              I already tried to include back slashs in the path to skip spaces...but doesn't work too...

              UPDATE 2

              This problem only occurs in Windows environment

              UPDATE 3

              I found a parcial solution:
              In the installed library folder, I have 2 files: libjsonfortran.a and libjsonfortran.dll.a
              If I delete the dll version...the shared library compilation get the .a static file and works good.

              So, How can I instruct the CMake to use always the static version only?

              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by raven-worx
              #5

              @fem_dev said in Load shared library: The specified module could not be found:

              a) No...I'am always running the main app using Qt Creator IDE

              your problem is that the dependency library (libjsonfortran.dll) cannot be found when you load "libLobular-Bearing-Plugin.dll" with QLIbrary. This is done by the OS which looks in certain paths for libaries.
              So either put the dll file next to your exe (which is in this case in QtCreators build folder) or update the PATH variable (can be done in the PROJECTS tab -> Run settings in QtCreator) with the folder containing the dll.
              When you release your exe you should anyway bundle the dependency libraries - probably next to the exe - afterall.

              Also i assume you are using mingw as compiler? If so you should be able to point to the .a file explicitly in the linking definition. (To choose between static and dynamic version of the lib)

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              4

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved