0

I created a QT app that needs two dlls files at runtime to resolve some function from them,

I have two questions:

1) Can i add that files to QT Resource to make the App loads them directly from resource without extracting to local path ?

2) If the Answer is "no"; How can i add a path to make the App searchs for that dlls in ?

Note: Names of dll files are stored in a ".a" lib that compiled with the App.

EDIT:

My situation is like the next:

let's say I built MingW QT 5.13.1 from the Source statically with "-openssl-runtime".

Now each app we build using that MingW will search for libcrypto-1_1.dll & libssl-1_1.dll in the same exe dir BUT the app can run without them only will face TLS initialization failed when requesting https urls.

Can i make the App load that dlls from Resource or force the App to search for them in another Path ?.

John
  • 165
  • 1
  • 12
  • If it's an .a lib, isn't it a statically linking library? It would be also useful to know on which OS your application works. You talk about dlls, and .a libs in the same time - it sounds confusing. – vahancho Nov 12 '19 at 08:47
  • By ".a" lib i mean Static ".lib" files – John Nov 12 '19 at 09:06
  • Well things are much clearer after your edit. All I can tell you is that the search paths for those libs are either buried somewhere in Qt configs or maybe as simple as using `QCoreApplication::addLibraryPath()` to add a path to wherever the libs are. Simplest is to put them in the same folder as the executable. – Maxim Paperno Nov 12 '19 at 09:24
  • I know if i add the dll in the same folder But i want to put them in another folder. `QCoreApplication::addLibraryPath()` didn't solved the problem; the same result – John Nov 12 '19 at 09:35

1 Answers1

1

First it's important to distinguish different ways of loading external libraries. Essentially:

  1. As a shared lib linked at compile-time into the application.
  2. A library loaded at run-time. With Qt for example this could be with QLibrary or as a plugin.

For #1, when the application is run, the linked library needs to be available at startup, before any code runs. So the answer to your 1st question is definitely no. As to where it should be located, the simplest is to put it into the same folder as the executable which depends on it. After that it gets complicated if you want to support different OSs... Eg. Windows has its own rules, whereas on Linux you have LD_LIBRARY_PATH at run-time or rpath at compile time (to name just a couple common options).

For #2 there is a lot more flexibility, including only loading the library(ies) if/when they're actually needed (which can, for example, improve startup time of your app). They can be located pretty much anywhere of your choosing (eg. a subfolder of your app distribution). But, I don't know about inside a resource file... I've never seen that mentioned or tried anywhere. I'm guessing not but it could be an interesting experiment! :)

Maxim Paperno
  • 4,485
  • 2
  • 18
  • 22
  • This library is a shared library linked at compile-time BUT the the exe executes it at the runtime after the app finish run (i.e: it doesn't require to be in the same exe folder, only when the app executes codes from it) like `QT -openssl-runtime` – John Nov 12 '19 at 07:15
  • @John I'm not really sure what you mean. If it's linked at compile-time then it needs to load for the app to start. If it's a library loaded after the app starts, then it doesn't. If by "QT -openssl-runtime" you mean the Qt build config option, then this is exactly what it does -- configures Qt to load OpenSSL libs at runtime after the app starts, vs. linking to the libs when Qt itself is built. https://www.qtcentre.org/threads/22546-run-time-vs-linked-OpenSSL-support – Maxim Paperno Nov 12 '19 at 07:35
  • I mean the dll behavior is like `-openssl-runtime`. The app can run without need for the dll to be in the same dir but when the App want to exec functions from dll the App needs the dll to be in a PATH. The dll execution is not `QLibrary` it is in ".a" lib compiled with the App. I Tried `SetDllDirectory` and it returns `true` but the same problem stills existing – John Nov 12 '19 at 08:22
  • @John, sorry, now I'm even more confused :) Sounds a lot like the libs you're talking about _are_ being loaded at runtime somehow (maybe with WinAPI like `LoadLIbrary`?), not linked at compile time. Otherwise the app simply wouldn't start w/out them. But then "in .a lib compiled with the app" makes me think you're maybe talking about static linkage (with MinGW/gcc?). It sounds like you have it working somehow already, so you should probably post an example of what you have now and what you're trying to do. Or maybe someone else will understand better. – Maxim Paperno Nov 12 '19 at 08:43
  • I edited the question and added an example for my problem, Sorry for unclear – John Nov 12 '19 at 09:05