I'm dynamically loading (whith dlopen()) a shared object (named libprofile1.so) from main.
In libprofile1.so I have defined factory function CreateProfile and class Profile. CreateProfile function creates an instance of Profile class and returns a pointer to it. Class Profile has a method pMethod.
In main, after loading libprofile1.so, I'm calling CreateProfile method which returns the pointer to the object of Profile class (call it p).
Afterwards, I'm calling pMethod method against object p (p->pMethod). In this method I'm dynamically loading other shared object (libdatasources.so).
In this shared object I have a factory function CreateDataSourceand class DataSource.
CreateDataSource function creates an instance of DataSource class and returns a pointer to it. DataSource class has method dsMethod.
As you can notice, structures of both shared objects are similar.
From pMethod after loading libdatasources.so I'm calling CreateDataSource method, which returns me a pointer to an instance of DataSource class, call it ds.
Then I'm calling dsMethod of ds object
(ds->dsMethod).
Now, the problem is following.
When I try to call dsMethod of ds object, shared object that I'm first loading (libprofile1.so) doesn't load. Actually dlopen() returns NULL. When I read dlerror after dlopen I get:
./libprofile1.so: undefined symbol: _ZN18DataSource13dsMethod
So if I have a call ds->Method, than first shared object doesn't load!
If I comment out call ds->dsMethod from the source, then my libprofile1.so and libdatasources.so are loaded without any problems.
I don't see the connection between the call of a method from the second SO, with loading first SO???
Maybe I don't know, but are there any constraints when dynamically loading a shared object, from a shared object that's also been dynamically loaded?
Btw, dlopen is used with RTLD_NOW|RTLD_GLOBAL. I tried with RTLD_LAZY, but still the same problem.
UPDATE:
Libraries are built in Eclipse. Options for G++ compiler and linker are the same for both libraries.
Here are G++ compiler:
-O0 -g3 -Wall -c -fmessage-length=0
and G++ linker:
-shared
options, pasted from Project Properties -> Settings -> Tool Settings
Thanks in advance.