Assume, I have a folder with my program and also another folder with external library.
QCoreApplication a(argc, argv);
QString path = "C:/etc/lib.dll";
qDebug() << "Ok\n";
qDebug() << "Error " << lib.errorString() << "\n";
qDebug() << "Not a library\n";
cannot load library lib.dll the specified module could not be found
That is Windows issue. The DLL will be looked at the current process directory and then in the system PATH. The code that is contained in some
C:\etc\lib.dll is behaving in its own process and unless very specific logic implemented will behave according to the system rule.
Please refer to MSDN article Dynamic-Link Library Search Order for details. If the source code for that lib.dll is available, it makes sense to examine LoadLibrary call. If there is no specific path provided then:
The first directory searched is the directory containing the image file used to create the calling process (for more information, see the CreateProcess function). Doing this allows private dynamic-link library (DLL) files associated with a process to be found without adding the process's installed directory to the PATH environment variable. If a relative path is specified, the entire relative path is appended to every token in the DLL search path list. To load a module from a relative path without searching any other path, use GetFullPathName to get a nonrelative path and call LoadLibrary with the nonrelative path. For more information on the DLL search order, see Dynamic-Link Library Search Order.