I dynamically load (whith dlopen() ) a shared object (named libprofile1.so ) from main .
In libprofile1.so I defined the factory function CreateProfile and class Profile . The CreateProfile function creates an instance of the Profile class and returns a pointer to it. The Profile class has a pMethod method.
Basically, after loading libprofile1.so , I call the CreateProfile method, which returns a pointer to an object of the Profile class (name it p ).
Subsequently, I call the pMethod method against the p object ( p->pMethod ). In this method, I dynamically load another shared object ( libdatasources.so ).
In this generic object, I have a factory function CreateDataSource and class DataSource .
The CreateDataSource function creates an instance of the DataSource class and returns a pointer to it. DataSource class has a dsMethod method.
As you can see, the structures of both common objects are similar.
From pMethod after loading libdatasources.so I call the CreateDataSource method, which returns me a pointer to an instance of the DataSource class, calls it ds . Then I call the dsMethod of the ds object
( ds->dsMethod ).
Now the problem is as follows.
When I try to call the dsMethod of the ds object, the generic object that I load first ( libprofile1.so ) does not load. In fact, dlopen() returns NULL . When I read dlerror after dlopen , I get:
./libprofile1.so: undefined symbol: _ZN18DataSource13dsMethod
So, if I have a call to ds->Method , then the first shared object does not load!
If I comment on the call to ds->dsMethod from the source, then my libprofile1.so and libdatasources.so load without problems.
I do not see the connection between the method call from the second SO, loading SO first ???
Maybe I donβt know, but are there any restrictions when dynamically loading a shared object from a shared object that was also dynamically loaded?
Btw, dlopen used with RTLD_NOW|RTLD_GLOBAL . I tried with RTLD_LAZY , but still the same problem.
UPDATE:
Libraries are built into Eclipse. The options for the g ++ compiler and linker are the same for both libraries.
Here is the g ++ compiler:
-O0 -g3 -Wall -c -fmessage-length=0
and g ++ linker:
-shared
inserted with Project Properties -> Settings -> Tool Settings
Thanks in advance.