Search code examples
qtqlibrary

Loading library with dependency with QLibrary


Suppose I have two libraries, A.dll and B.dll. The library A depends on B. I want to load A into my project.

My project is in C:/Project. If I keep both A.dll and B.dll in C:/Project, I can load A with:

QLibrary lib("A"); 
lib.load();

This works fine. load() will return false if B.dll isn't in C:/Project, though.

The problem is I want to keep both A.dll and B.dll in C:/Project/lib. But when I move both libs to that location and try to load:

QLibrary lib("C:/Project/lib/A");
lib.load();

It fails. But this works if I keep A.dll in C:/Project/lib and B.dll in C:/Project.

How can I keep both libs in C:/Project/liband have A.dll load successfully?

Edit: the error message I get is "Cannot load library C:/Project/lib/A . The specified module could not be found."


Solution

  • Try using SetDllDirectory, see http://msdn.microsoft.com/en-us/library/ms686203%28VS.85%29.aspx