1

QLibrary works fine to obtain one set of function pointers from one instance of an .so library. However, it does not work when trying to obtain two different instances of function pointers from the same .so file. Both sets of pointers point to the same locations in memory, making them redundant and not useful. According to the docs for Qt 5.12 QLibrary:

Multiple instances of QLibrary can be used to access the same physical library.

They don't say how this is supposed to work, so should you just be able to load two instances of the same .so file with two QLibraries? Or am I misunderstanding and you really need two copies of the same library file?

Code below in case my explanation is not clear:

QLibrary loader1("lib.so");
loader1.load();
foo1 = reinterpret_cast<foo>(loader1.resolve("foo"));
foo1();

QLibrary loader2("lib.so");
loader2.load();
foo2 = reinterpret_cast<foo>(loader2.resolve("foo"));
foo2();

// foo1 and foo2 both call the same instance of the foo function instead of separate instances
ijk
  • 47
  • 5
  • "Multiple instances of QLibrary can be used" means that if you use library A and it does `QLibrary("libcrypto.so")` then it will not break library B that also does `QLibrary("libcrypto.so")` It does not mean that each instance of a QLibrary object results in a separate code of the code.... in fact that's what .so (**shared object**) is designed to prevent. – Ben Voigt Jul 20 '20 at 19:47

1 Answers1

1

The text you quote is the response:

Multiple instances of QLibrary can be used to access the same physical library.

Two instances:

QLibrary loader1("lib.so");
QLibrary loader2("lib.so");

but the same physical library. So the functions are at the same memory location.

Once the library is loaded, you use one library.

There is a way to do what you need, but it isn't Qt.

Manuel
  • 2,526
  • 1
  • 13
  • 17
  • I was afraid that would be the case. I'll see if I can rewrite my library to be more generic internally. Thanks. – ijk Jul 20 '20 at 20:15