Newbie question. Suppose there is a third party library ClassLibrary.so, which contains the class definition of a ClassTest and I don't have access to the source of ClassLibrary.so. Can I use ClassTest in my code with dlopen and dlsym? Personally, I would like to compile with ClassLibrary.so but the client wants to use dlopen and dlsym.
I have not tried much as I don't know how to start. I went through this article https://www.linuxjournal.com/article/3687 but it seems that this article requires access to the source of library to create a function that returns a pointer to the class within the source and use this function with dlopen and dlsym.
Maybe.
If the
ClassLibrary.soexports all the methods ofClassTestandClassLibrary.hprovides a declaration forClassTestand that declaration actually matches that one used whenClassLibrary.sowas built, and you know exact compiler version and flags used to buildClassLibrary.so.In practice you probably can't know the compiler version (even if
strings -a ClassLibrary.sosays something likeGCC 10.0.1, that's not necessarily sufficient), nor the build flags, and you can't know whether developers ofClassLibrary.sohave played any tricks with the declaration ofClassTest(if they even provided such declaration).